11//! Completion of names from the current scope in expression position.
22
3- use hir:: { HasVisibility , Module , ScopeDef } ;
3+ use hir:: ScopeDef ;
44use syntax:: ast;
55
66use crate :: {
@@ -9,23 +9,6 @@ use crate::{
99 CompletionContext , Completions ,
1010} ;
1111
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-
2912pub ( crate ) fn complete_expr_path (
3013 acc : & mut Completions ,
3114 ctx : & CompletionContext < ' _ > ,
@@ -54,6 +37,12 @@ pub(crate) fn complete_expr_path(
5437 let wants_mut_token =
5538 ref_expr_parent. as_ref ( ) . map ( |it| it. mut_token ( ) . is_none ( ) ) . unwrap_or ( false ) ;
5639
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+
5746 let add_assoc_item = |acc : & mut Completions , item| match item {
5847 hir:: AssocItem :: Function ( func) => acc. add_function ( ctx, path_ctx, func, None ) ,
5948 hir:: AssocItem :: Const ( ct) => acc. add_const ( ctx, ct) ,
@@ -98,7 +87,7 @@ pub(crate) fn complete_expr_path(
9887 hir:: PathResolution :: Def ( hir:: ModuleDef :: Module ( module) ) => {
9988 let module_scope = module. scope ( ctx. db , Some ( ctx. module ) ) ;
10089 for ( name, def) in module_scope {
101- if scope_def_applicable ( def, ctx , Some ( module ) ) {
90+ if scope_def_applicable ( def) {
10291 acc. add_path_resolution (
10392 ctx,
10493 path_ctx,
@@ -244,7 +233,7 @@ pub(crate) fn complete_expr_path(
244233 [ ..] => acc. add_path_resolution ( ctx, path_ctx, name, def, doc_aliases) ,
245234 }
246235 }
247- _ if scope_def_applicable ( def, ctx , None ) => {
236+ _ if scope_def_applicable ( def) => {
248237 acc. add_path_resolution ( ctx, path_ctx, name, def, doc_aliases)
249238 }
250239 _ => ( ) ,
0 commit comments