aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-03 11:10:55 +0000
committerGitHub <[email protected]>2020-02-03 11:10:55 +0000
commit5b1b2cac39d88e730d594f951ab6613eab5ee498 (patch)
treefc8ccfb102a780c6789cb640482210db2d3dd2aa /crates
parent52456c44901c8c38c8bcb742ebe305484af8f36f (diff)
parent01d59f4a322c019cb9cbc2935fe8e7ba432bcd3d (diff)
Merge #2990
2990: Use name only when searching for an import candidate r=me a=SomeoneToIgnore Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/assists/auto_import.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs
index 2629f00e6..7fd1f0e7d 100644
--- a/crates/ra_assists/src/assists/auto_import.rs
+++ b/crates/ra_assists/src/assists/auto_import.rs
@@ -1,7 +1,7 @@
1use hir::{db::HirDatabase, ModPath}; 1use hir::{db::HirDatabase, ModPath};
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, AstNode}, 3 ast::{self, AstNode},
4 SyntaxKind::USE_ITEM, 4 SyntaxKind::{NAME_REF, USE_ITEM},
5 SyntaxNode, 5 SyntaxNode,
6}; 6};
7 7
@@ -36,6 +36,8 @@ pub(crate) fn auto_import<F: ImportsLocator>(
36 if path_to_import_syntax.ancestors().find(|ancestor| ancestor.kind() == USE_ITEM).is_some() { 36 if path_to_import_syntax.ancestors().find(|ancestor| ancestor.kind() == USE_ITEM).is_some() {
37 return None; 37 return None;
38 } 38 }
39 let name_to_import =
40 path_to_import_syntax.descendants().find(|child| child.kind() == NAME_REF)?;
39 41
40 let module = path_to_import_syntax.ancestors().find_map(ast::Module::cast); 42 let module = path_to_import_syntax.ancestors().find_map(ast::Module::cast);
41 let position = match module.and_then(|it| it.item_list()) { 43 let position = match module.and_then(|it| it.item_list()) {
@@ -52,7 +54,7 @@ pub(crate) fn auto_import<F: ImportsLocator>(
52 } 54 }
53 55
54 let proposed_imports = imports_locator 56 let proposed_imports = imports_locator
55 .find_imports(&path_to_import_syntax.to_string()) 57 .find_imports(&name_to_import.to_string())
56 .into_iter() 58 .into_iter()
57 .filter_map(|module_def| module_with_name_to_import.find_use_path(ctx.db, module_def)) 59 .filter_map(|module_def| module_with_name_to_import.find_use_path(ctx.db, module_def))
58 .filter(|use_path| !use_path.segments.is_empty()) 60 .filter(|use_path| !use_path.segments.is_empty())
@@ -121,21 +123,29 @@ mod tests {
121 r" 123 r"
122 use PubMod::PubStruct1; 124 use PubMod::PubStruct1;
123 125
124 PubStruct2<|> 126 struct Test {
127 test: Pub<|>Struct2<u8>,
128 }
125 129
126 pub mod PubMod { 130 pub mod PubMod {
127 pub struct PubStruct1; 131 pub struct PubStruct1;
128 pub struct PubStruct2; 132 pub struct PubStruct2<T> {
133 _t: T,
134 }
129 } 135 }
130 ", 136 ",
131 r" 137 r"
132 use PubMod::{PubStruct2, PubStruct1}; 138 use PubMod::{PubStruct2, PubStruct1};
133 139
134 PubStruct2<|> 140 struct Test {
141 test: Pub<|>Struct2<u8>,
142 }
135 143
136 pub mod PubMod { 144 pub mod PubMod {
137 pub struct PubStruct1; 145 pub struct PubStruct1;
138 pub struct PubStruct2; 146 pub struct PubStruct2<T> {
147 _t: T,
148 }
139 } 149 }
140 ", 150 ",
141 ); 151 );