diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2024-05-22 13:49:56 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2024-05-22 14:05:24 +0200 |
| commit | 5992af6506088db3f907744b5a09e0ae99e83de4 (patch) | |
| tree | 8e2c89bf97a428fb0ea741c41d972264aedd6637 /src/tools/rust-analyzer/crates/hir | |
| parent | 9f4b6517208d77556a919789ed285e0c6f67bbb5 (diff) | |
| download | rust-5992af6506088db3f907744b5a09e0ae99e83de4.tar.gz rust-5992af6506088db3f907744b5a09e0ae99e83de4.zip | |
fix: Fix general find-path inconsistencies
Diffstat (limited to 'src/tools/rust-analyzer/crates/hir')
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir/src/lib.rs | 9 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir/src/term_search/expr.rs | 15 |
2 files changed, 11 insertions, 13 deletions
diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs index 85f33a10fcb..773ac01e0e3 100644 --- a/src/tools/rust-analyzer/crates/hir/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs @@ -789,7 +789,7 @@ impl Module { /// Finds a path that can be used to refer to the given item from within /// this module, if possible. - pub fn find_use_path( + pub fn find_path( self, db: &dyn DefDatabase, item: impl Into<ItemInNs>, @@ -800,6 +800,8 @@ impl Module { db, item.into().into(), self.into(), + PrefixKind::Plain, + false, prefer_no_std, prefer_prelude, ) @@ -807,7 +809,7 @@ impl Module { /// Finds a path that can be used to refer to the given item from within /// this module, if possible. This is used for returning import paths for use-statements. - pub fn find_use_path_prefixed( + pub fn find_use_path( self, db: &dyn DefDatabase, item: impl Into<ItemInNs>, @@ -815,11 +817,12 @@ impl Module { prefer_no_std: bool, prefer_prelude: bool, ) -> Option<ModPath> { - hir_def::find_path::find_path_prefixed( + hir_def::find_path::find_path( db, item.into().into(), self.into(), prefix_kind, + true, prefer_no_std, prefer_prelude, ) diff --git a/src/tools/rust-analyzer/crates/hir/src/term_search/expr.rs b/src/tools/rust-analyzer/crates/hir/src/term_search/expr.rs index 9f56a1ee55d..45c0dd8da75 100644 --- a/src/tools/rust-analyzer/crates/hir/src/term_search/expr.rs +++ b/src/tools/rust-analyzer/crates/hir/src/term_search/expr.rs @@ -33,16 +33,11 @@ fn mod_item_path( }); let m = sema_scope.module(); - match name_hit_count { - Some(0..=1) | None => m.find_use_path(db.upcast(), *def, prefer_no_std, prefer_prelude), - Some(_) => m.find_use_path_prefixed( - db.upcast(), - *def, - PrefixKind::ByCrate, - prefer_no_std, - prefer_prelude, - ), - } + let prefix = match name_hit_count { + Some(0..=1) | None => PrefixKind::Plain, + Some(_) => PrefixKind::ByCrate, + }; + m.find_use_path(db.upcast(), *def, prefix, prefer_no_std, prefer_prelude) } /// Helper function to get path to `ModuleDef` as string |
