@@ -9,6 +9,23 @@ use syntax::{ast, AstNode, SyntaxNode};
9
9
10
10
use crate :: assist_config:: InsertUseConfig ;
11
11
12
+ #[ derive( Debug ) ]
13
+ pub ( crate ) enum ImportCandidate {
14
+ /// Simple name like 'HashMap'
15
+ UnqualifiedName ( String ) ,
16
+ /// First part of the qualified name.
17
+ /// For 'std::collections::HashMap', that will be 'std'.
18
+ QualifierStart ( String ) ,
19
+ /// A trait associated function (with no self parameter) or associated constant.
20
+ /// For 'test_mod::TestEnum::test_function', `Type` is the `test_mod::TestEnum` expression type
21
+ /// and `String` is the `test_function`
22
+ TraitAssocItem ( hir:: Type , String ) ,
23
+ /// A trait method with self parameter.
24
+ /// For 'test_enum.test_method()', `Type` is the `test_enum` expression type
25
+ /// and `String` is the `test_method`
26
+ TraitMethod ( hir:: Type , String ) ,
27
+ }
28
+
12
29
#[ derive( Debug ) ]
13
30
pub ( crate ) struct ImportAssets {
14
31
import_candidate : ImportCandidate ,
@@ -17,23 +34,7 @@ pub(crate) struct ImportAssets {
17
34
}
18
35
19
36
impl ImportAssets {
20
- pub ( crate ) fn new ( ctx : & crate :: assist_context:: AssistContext ) -> Option < Self > {
21
- if let Some ( path_under_caret) = ctx. find_node_at_offset_with_descend :: < ast:: Path > ( ) {
22
- Self :: for_regular_path ( path_under_caret, & ctx. sema )
23
- } else {
24
- Self :: for_method_call ( ctx. find_node_at_offset_with_descend ( ) ?, & ctx. sema )
25
- }
26
- }
27
-
28
- pub ( crate ) fn syntax_under_caret ( & self ) -> & SyntaxNode {
29
- & self . syntax_under_caret
30
- }
31
-
32
- pub ( crate ) fn import_candidate ( & self ) -> & ImportCandidate {
33
- & self . import_candidate
34
- }
35
-
36
- fn for_method_call (
37
+ pub ( crate ) fn for_method_call (
37
38
method_call : ast:: MethodCallExpr ,
38
39
sema : & Semantics < RootDatabase > ,
39
40
) -> Option < Self > {
@@ -46,7 +47,7 @@ impl ImportAssets {
46
47
} )
47
48
}
48
49
49
- fn for_regular_path (
50
+ pub ( crate ) fn for_regular_path (
50
51
path_under_caret : ast:: Path ,
51
52
sema : & Semantics < RootDatabase > ,
52
53
) -> Option < Self > {
@@ -63,6 +64,14 @@ impl ImportAssets {
63
64
} )
64
65
}
65
66
67
+ pub ( crate ) fn syntax_under_caret ( & self ) -> & SyntaxNode {
68
+ & self . syntax_under_caret
69
+ }
70
+
71
+ pub ( crate ) fn import_candidate ( & self ) -> & ImportCandidate {
72
+ & self . import_candidate
73
+ }
74
+
66
75
fn get_search_query ( & self ) -> & str {
67
76
match & self . import_candidate {
68
77
ImportCandidate :: UnqualifiedName ( name) => name,
@@ -182,25 +191,8 @@ impl ImportAssets {
182
191
}
183
192
}
184
193
185
- #[ derive( Debug ) ]
186
- pub ( crate ) enum ImportCandidate {
187
- /// Simple name like 'HashMap'
188
- UnqualifiedName ( String ) ,
189
- /// First part of the qualified name.
190
- /// For 'std::collections::HashMap', that will be 'std'.
191
- QualifierStart ( String ) ,
192
- /// A trait associated function (with no self parameter) or associated constant.
193
- /// For 'test_mod::TestEnum::test_function', `Type` is the `test_mod::TestEnum` expression type
194
- /// and `String` is the `test_function`
195
- TraitAssocItem ( hir:: Type , String ) ,
196
- /// A trait method with self parameter.
197
- /// For 'test_enum.test_method()', `Type` is the `test_enum` expression type
198
- /// and `String` is the `test_method`
199
- TraitMethod ( hir:: Type , String ) ,
200
- }
201
-
202
194
impl ImportCandidate {
203
- pub ( crate ) fn for_method_call (
195
+ fn for_method_call (
204
196
sema : & Semantics < RootDatabase > ,
205
197
method_call : & ast:: MethodCallExpr ,
206
198
) -> Option < Self > {
@@ -213,7 +205,7 @@ impl ImportCandidate {
213
205
) )
214
206
}
215
207
216
- pub ( crate ) fn for_regular_path (
208
+ fn for_regular_path (
217
209
sema : & Semantics < RootDatabase > ,
218
210
path_under_caret : & ast:: Path ,
219
211
) -> Option < Self > {
0 commit comments