@@ -11,12 +11,9 @@ use crate::{
11
11
} ;
12
12
13
13
pub ( crate ) fn complete_use_tree ( acc : & mut Completions , ctx : & CompletionContext ) {
14
- let ( is_absolute_path, qualifier) = match ctx. path_context {
14
+ let ( & is_absolute_path, qualifier) = match & ctx. path_context {
15
15
Some ( PathCompletionCtx {
16
- kind : Some ( PathKind :: Use ) ,
17
- is_absolute_path,
18
- ref qualifier,
19
- ..
16
+ kind : Some ( PathKind :: Use ) , is_absolute_path, qualifier, ..
20
17
} ) => ( is_absolute_path, qualifier) ,
21
18
_ => return ,
22
19
} ;
@@ -45,13 +42,9 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
45
42
if let Some ( list) = ctx. token . ancestors ( ) . find_map ( ast:: UseTreeList :: cast) {
46
43
let use_tree = list. parent_use_tree ( ) ;
47
44
if use_tree. path ( ) . as_ref ( ) == Some ( path) {
48
- for tree in list. use_trees ( ) {
49
- if tree. is_simple_path ( ) {
50
- if let Some ( name) =
51
- tree. path ( ) . and_then ( |path| path. as_single_name_ref ( ) )
52
- {
53
- already_imported_names. insert ( name. to_string ( ) ) ;
54
- }
45
+ for tree in list. use_trees ( ) . filter ( |tree| tree. is_simple_path ( ) ) {
46
+ if let Some ( name) = tree. path ( ) . and_then ( |path| path. as_single_name_ref ( ) ) {
47
+ already_imported_names. insert ( name. to_string ( ) ) ;
55
48
}
56
49
}
57
50
}
@@ -62,14 +55,14 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
62
55
let module_scope = module. scope ( ctx. db , Some ( ctx. module ) ) ;
63
56
let unknown_is_current = |name : & hir:: Name | {
64
57
matches ! (
65
- ctx. name_syntax. as_ref( ) ,
66
- Some ( ast:: NameLike :: NameRef ( name_ref) )
67
- if name_ref. syntax( ) . text( ) == name. to_smol_str( ) . as_str( )
58
+ ctx. name_ref( ) ,
59
+ Some ( name_ref) if name_ref. syntax( ) . text( ) == name. to_smol_str( ) . as_str( )
68
60
)
69
61
} ;
70
62
for ( name, def) in module_scope {
71
- let is_name_already_imported =
72
- already_imported_names. contains ( name. as_text ( ) . unwrap ( ) . as_str ( ) ) ;
63
+ let is_name_already_imported = name
64
+ . as_text ( )
65
+ . map_or ( false , |text| already_imported_names. contains ( text. as_str ( ) ) ) ;
73
66
74
67
let add_resolution = match def {
75
68
ScopeDef :: Unknown if unknown_is_current ( & name) => {
0 commit comments