@@ -9,6 +9,23 @@ use syntax::{ast, AstNode, SyntaxNode};
99
1010use crate :: assist_config:: InsertUseConfig ;
1111
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+
1229#[ derive( Debug ) ]
1330pub ( crate ) struct ImportAssets {
1431 import_candidate : ImportCandidate ,
@@ -17,23 +34,7 @@ pub(crate) struct ImportAssets {
1734}
1835
1936impl 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 (
3738 method_call : ast:: MethodCallExpr ,
3839 sema : & Semantics < RootDatabase > ,
3940 ) -> Option < Self > {
@@ -46,7 +47,7 @@ impl ImportAssets {
4647 } )
4748 }
4849
49- fn for_regular_path (
50+ pub ( crate ) fn for_regular_path (
5051 path_under_caret : ast:: Path ,
5152 sema : & Semantics < RootDatabase > ,
5253 ) -> Option < Self > {
@@ -63,6 +64,14 @@ impl ImportAssets {
6364 } )
6465 }
6566
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+
6675 fn get_search_query ( & self ) -> & str {
6776 match & self . import_candidate {
6877 ImportCandidate :: UnqualifiedName ( name) => name,
@@ -182,25 +191,8 @@ impl ImportAssets {
182191 }
183192}
184193
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-
202194impl ImportCandidate {
203- pub ( crate ) fn for_method_call (
195+ fn for_method_call (
204196 sema : & Semantics < RootDatabase > ,
205197 method_call : & ast:: MethodCallExpr ,
206198 ) -> Option < Self > {
@@ -213,7 +205,7 @@ impl ImportCandidate {
213205 ) )
214206 }
215207
216- pub ( crate ) fn for_regular_path (
208+ fn for_regular_path (
217209 sema : & Semantics < RootDatabase > ,
218210 path_under_caret : & ast:: Path ,
219211 ) -> Option < Self > {
0 commit comments