From eb51abdc646e11b8c23fee83b6f052d3dde87985 Mon Sep 17 00:00:00 2001 From: Steffen Lyngbaek Date: Wed, 18 Mar 2020 16:15:32 -0700 Subject: Fixes to more accurately give complete_scope completions - Exclude const, static, functions form is_pat_binding_and_path (there might be more?) - Add a check to filter out Record Fields - Fix tests --- crates/ra_ide/src/completion/complete_pattern.rs | 28 ++++++++++++++++++++++ crates/ra_ide/src/completion/complete_scope.rs | 17 ++++--------- crates/ra_ide/src/completion/completion_context.rs | 8 ++++--- 3 files changed, 38 insertions(+), 15 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/completion/complete_pattern.rs b/crates/ra_ide/src/completion/complete_pattern.rs index cb84bb934..e8e676a4c 100644 --- a/crates/ra_ide/src/completion/complete_pattern.rs +++ b/crates/ra_ide/src/completion/complete_pattern.rs @@ -55,6 +55,20 @@ mod tests { ); assert_debug_snapshot!(completions, @r###" [ + CompletionItem { + label: "Bar", + source_range: [246; 246), + delete: [246; 246), + insert: "Bar", + kind: Struct, + }, + CompletionItem { + label: "E", + source_range: [246; 246), + delete: [246; 246), + insert: "E", + kind: Enum, + }, CompletionItem { label: "E", source_range: [246; 246), @@ -69,6 +83,13 @@ mod tests { insert: "X", kind: EnumVariant, }, + CompletionItem { + label: "X", + source_range: [246; 246), + delete: [246; 246), + insert: "X", + kind: EnumVariant, + }, CompletionItem { label: "Z", source_range: [246; 246), @@ -83,6 +104,13 @@ mod tests { insert: "m", kind: Module, }, + CompletionItem { + label: "m", + source_range: [246; 246), + delete: [246; 246), + insert: "m", + kind: Module, + }, ] "###); } diff --git a/crates/ra_ide/src/completion/complete_scope.rs b/crates/ra_ide/src/completion/complete_scope.rs index 6b0621081..1cb2ed070 100644 --- a/crates/ra_ide/src/completion/complete_scope.rs +++ b/crates/ra_ide/src/completion/complete_scope.rs @@ -1,7 +1,7 @@ //! Completion of names from the current scope, e.g. locals and imported items. use crate::completion::{CompletionContext, Completions}; -use hir::ScopeDef; +use hir::{ModuleDef, ScopeDef}; pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.is_trivial_path && !ctx.is_pat_binding_and_path { @@ -9,7 +9,10 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { } ctx.scope().process_all_names(&mut |name, res| match (ctx.is_pat_binding_and_path, &res) { - (true, ScopeDef::Local(..)) => {} + (true, ScopeDef::ModuleDef(ModuleDef::Function(..))) => (), + (true, ScopeDef::ModuleDef(ModuleDef::Static(..))) => (), + (true, ScopeDef::ModuleDef(ModuleDef::Const(..))) => (), + (true, ScopeDef::Local(..)) => (), _ => acc.add_resolution(ctx, name.to_string(), &res), }); } @@ -71,16 +74,6 @@ mod tests { insert: "Enum", kind: Enum, }, - CompletionItem { - label: "quux(…)", - source_range: [231; 233), - delete: [231; 233), - insert: "quux(${1:x})$0", - kind: Function, - lookup: "quux", - detail: "fn quux(x: Option)", - trigger_call_info: true, - }, ] "### ); diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index f9d4154d8..65bdac182 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -197,9 +197,11 @@ impl<'a> CompletionContext<'a> { self.is_pat_binding = true; } - let bind_pat_string = bind_pat.syntax().to_string(); - if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") { - self.is_pat_binding_and_path = true; + if parent.and_then(ast::RecordFieldPatList::cast).is_none() { + let bind_pat_string = bind_pat.syntax().to_string(); + if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") { + self.is_pat_binding_and_path = true; + } } } if is_node::(name.syntax()) { -- cgit v1.2.3