diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-24 13:46:55 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-24 13:46:55 +0100 |
commit | c3defe2532ba6ffd12a13bcbc8fdeda037665efc (patch) | |
tree | 831bf4dd44ec83d927face4ba17e57dcdeab7fbe /crates/ra_ide_db/src/defs.rs | |
parent | 0e5095d3cac11d4b569c6e1594bd07937556c812 (diff) | |
parent | 58680cb08ea535e1fb567416fa3466a744a01b99 (diff) |
Merge #5518
5518: Use resolved paths in SSR rules r=matklad a=davidlattimore
The main user-visible changes are:
* SSR now matches paths based on whether they resolve to the same thing instead of whether they're written the same.
* So `foo()` won't match `foo()` if it's a different function `foo()`, but will match `bar::foo()` if it's the same `foo`.
* Paths in the replacement will now be rendered with appropriate qualification for their context.
* For example `foo::Bar` will render as just `Bar` inside the module `foo`, but might render as `baz::foo::Bar` from elsewhere.
* This means that all paths in the search pattern and replacement template must be able to be resolved.
* It now also matters where you invoke SSR from, since paths are resolved relative to wherever that is.
* Search now uses find-uses on paths to locate places to try matching. This means that when a path is present in the pattern, search will generally be pretty fast.
* Function calls can now match method calls again, but this time only if they resolve to the same function.
Co-authored-by: David Lattimore <[email protected]>
Diffstat (limited to 'crates/ra_ide_db/src/defs.rs')
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index e06b189a0..f391a8e43 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -290,20 +290,25 @@ pub fn classify_name_ref( | |||
290 | 290 | ||
291 | let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; | 291 | let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; |
292 | let resolved = sema.resolve_path(&path)?; | 292 | let resolved = sema.resolve_path(&path)?; |
293 | let res = match resolved { | 293 | Some(NameRefClass::Definition(resolved.into())) |
294 | PathResolution::Def(def) => Definition::ModuleDef(def), | 294 | } |
295 | PathResolution::AssocItem(item) => { | 295 | |
296 | let def = match item { | 296 | impl From<PathResolution> for Definition { |
297 | hir::AssocItem::Function(it) => it.into(), | 297 | fn from(path_resolution: PathResolution) -> Self { |
298 | hir::AssocItem::Const(it) => it.into(), | 298 | match path_resolution { |
299 | hir::AssocItem::TypeAlias(it) => it.into(), | 299 | PathResolution::Def(def) => Definition::ModuleDef(def), |
300 | }; | 300 | PathResolution::AssocItem(item) => { |
301 | Definition::ModuleDef(def) | 301 | let def = match item { |
302 | hir::AssocItem::Function(it) => it.into(), | ||
303 | hir::AssocItem::Const(it) => it.into(), | ||
304 | hir::AssocItem::TypeAlias(it) => it.into(), | ||
305 | }; | ||
306 | Definition::ModuleDef(def) | ||
307 | } | ||
308 | PathResolution::Local(local) => Definition::Local(local), | ||
309 | PathResolution::TypeParam(par) => Definition::TypeParam(par), | ||
310 | PathResolution::Macro(def) => Definition::Macro(def), | ||
311 | PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def), | ||
302 | } | 312 | } |
303 | PathResolution::Local(local) => Definition::Local(local), | 313 | } |
304 | PathResolution::TypeParam(par) => Definition::TypeParam(par), | ||
305 | PathResolution::Macro(def) => Definition::Macro(def), | ||
306 | PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def), | ||
307 | }; | ||
308 | Some(NameRefClass::Definition(res)) | ||
309 | } | 314 | } |