1
1
//! Completion of names from the current scope in expression position.
2
2
3
- use hir:: { HasVisibility , Module , ScopeDef } ;
3
+ use hir:: ScopeDef ;
4
4
use syntax:: ast;
5
5
6
6
use crate :: {
@@ -9,23 +9,6 @@ use crate::{
9
9
CompletionContext , Completions ,
10
10
} ;
11
11
12
- fn scope_def_applicable (
13
- def : ScopeDef ,
14
- ctx : & CompletionContext < ' _ > ,
15
- module : Option < & Module > ,
16
- ) -> bool {
17
- match ( def, module) {
18
- ( ScopeDef :: GenericParam ( hir:: GenericParam :: LifetimeParam ( _) ) | ScopeDef :: Label ( _) , _) => {
19
- false
20
- }
21
- ( ScopeDef :: ModuleDef ( hir:: ModuleDef :: Macro ( mac) ) , _) => mac. is_fn_like ( ctx. db ) ,
22
- ( ScopeDef :: ModuleDef ( hir:: ModuleDef :: Function ( f) ) , Some ( m) ) => {
23
- f. is_visible_from ( ctx. db , * m)
24
- }
25
- _ => true ,
26
- }
27
- }
28
-
29
12
pub ( crate ) fn complete_expr_path (
30
13
acc : & mut Completions ,
31
14
ctx : & CompletionContext < ' _ > ,
@@ -54,6 +37,12 @@ pub(crate) fn complete_expr_path(
54
37
let wants_mut_token =
55
38
ref_expr_parent. as_ref ( ) . map ( |it| it. mut_token ( ) . is_none ( ) ) . unwrap_or ( false ) ;
56
39
40
+ let scope_def_applicable = |def| match def {
41
+ ScopeDef :: GenericParam ( hir:: GenericParam :: LifetimeParam ( _) ) | ScopeDef :: Label ( _) => false ,
42
+ ScopeDef :: ModuleDef ( hir:: ModuleDef :: Macro ( mac) ) => mac. is_fn_like ( ctx. db ) ,
43
+ _ => true ,
44
+ } ;
45
+
57
46
let add_assoc_item = |acc : & mut Completions , item| match item {
58
47
hir:: AssocItem :: Function ( func) => acc. add_function ( ctx, path_ctx, func, None ) ,
59
48
hir:: AssocItem :: Const ( ct) => acc. add_const ( ctx, ct) ,
@@ -98,7 +87,7 @@ pub(crate) fn complete_expr_path(
98
87
hir:: PathResolution :: Def ( hir:: ModuleDef :: Module ( module) ) => {
99
88
let module_scope = module. scope ( ctx. db , Some ( ctx. module ) ) ;
100
89
for ( name, def) in module_scope {
101
- if scope_def_applicable ( def, ctx , Some ( module ) ) {
90
+ if scope_def_applicable ( def) {
102
91
acc. add_path_resolution (
103
92
ctx,
104
93
path_ctx,
@@ -244,7 +233,7 @@ pub(crate) fn complete_expr_path(
244
233
[ ..] => acc. add_path_resolution ( ctx, path_ctx, name, def, doc_aliases) ,
245
234
}
246
235
}
247
- _ if scope_def_applicable ( def, ctx , None ) => {
236
+ _ if scope_def_applicable ( def) => {
248
237
acc. add_path_resolution ( ctx, path_ctx, name, def, doc_aliases)
249
238
}
250
239
_ => ( ) ,
0 commit comments