File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
crates/ra_assists/src/assists Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change 1
1
use hir:: { db:: HirDatabase , ModPath } ;
2
2
use ra_syntax:: {
3
3
ast:: { self , AstNode } ,
4
- SyntaxKind :: USE_ITEM ,
4
+ SyntaxKind :: { NAME_REF , USE_ITEM } ,
5
5
SyntaxNode ,
6
6
} ;
7
7
@@ -36,6 +36,8 @@ pub(crate) fn auto_import<F: ImportsLocator>(
36
36
if path_to_import_syntax. ancestors ( ) . find ( |ancestor| ancestor. kind ( ) == USE_ITEM ) . is_some ( ) {
37
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
42
let module = path_to_import_syntax. ancestors ( ) . find_map ( ast:: Module :: cast) ;
41
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
56
let proposed_imports = imports_locator
55
- . find_imports ( & path_to_import_syntax . to_string ( ) )
57
+ . find_imports ( & name_to_import . to_string ( ) )
56
58
. into_iter ( )
57
59
. filter_map ( |module_def| module_with_name_to_import. find_use_path ( ctx. db , module_def) )
58
60
. filter ( |use_path| !use_path. segments . is_empty ( ) )
@@ -121,21 +123,29 @@ mod tests {
121
123
r"
122
124
use PubMod::PubStruct1;
123
125
124
- PubStruct2<|>
126
+ struct Test {
127
+ test: Pub<|>Struct2<u8>,
128
+ }
125
129
126
130
pub mod PubMod {
127
131
pub struct PubStruct1;
128
- pub struct PubStruct2;
132
+ pub struct PubStruct2<T> {
133
+ _t: T,
134
+ }
129
135
}
130
136
" ,
131
137
r"
132
138
use PubMod::{PubStruct2, PubStruct1};
133
139
134
- PubStruct2<|>
140
+ struct Test {
141
+ test: Pub<|>Struct2<u8>,
142
+ }
135
143
136
144
pub mod PubMod {
137
145
pub struct PubStruct1;
138
- pub struct PubStruct2;
146
+ pub struct PubStruct2<T> {
147
+ _t: T,
148
+ }
139
149
}
140
150
" ,
141
151
) ;
You can’t perform that action at this time.
0 commit comments