From e475bcdcc671161cf97d86d116a834c540f75f7c Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 6 Jun 2021 20:02:26 +0200 Subject: Simplify CompletionContext by introducing a path CallKind enum --- crates/ide_completion/src/completions/dot.rs | 4 ++-- crates/ide_completion/src/completions/postfix.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ide_completion/src/completions') diff --git a/crates/ide_completion/src/completions/dot.rs b/crates/ide_completion/src/completions/dot.rs index e0a7021fd..22844c2ae 100644 --- a/crates/ide_completion/src/completions/dot.rs +++ b/crates/ide_completion/src/completions/dot.rs @@ -4,7 +4,7 @@ use either::Either; use hir::{HasVisibility, ScopeDef}; use rustc_hash::FxHashSet; -use crate::{context::CompletionContext, Completions}; +use crate::{context::CompletionContext, patterns::ImmediateLocation, Completions}; /// Complete dot accesses, i.e. fields or methods. pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { @@ -18,7 +18,7 @@ pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { _ => return, }; - if ctx.is_call { + if matches!(ctx.completion_location, Some(ImmediateLocation::MethodCall { .. })) { cov_mark::hit!(test_no_struct_field_completion_for_method_call); } else { complete_fields(ctx, &receiver_ty, |field, ty| match field { diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs index 86bbb58e2..86eb21714 100644 --- a/crates/ide_completion/src/completions/postfix.rs +++ b/crates/ide_completion/src/completions/postfix.rs @@ -24,7 +24,7 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { } let (dot_receiver, receiver_is_ambiguous_float_literal) = match &ctx.completion_location { - Some(ImmediateLocation::MethodCall { receiver: Some(it) }) => (it, false), + Some(ImmediateLocation::MethodCall { receiver: Some(it), .. }) => (it, false), Some(ImmediateLocation::FieldAccess { receiver: Some(it), receiver_is_ambiguous_float_literal, -- cgit v1.2.3 From 4eabcb2c01209065a231e616ba646ba63f68f00d Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 7 Jun 2021 12:29:46 +0200 Subject: Move more things into PathCompletionContext --- crates/ide_completion/src/completions/dot.rs | 2 +- crates/ide_completion/src/completions/flyimport.rs | 6 +++--- crates/ide_completion/src/completions/keyword.rs | 11 ++++++----- crates/ide_completion/src/completions/qualified_path.rs | 4 ++-- crates/ide_completion/src/completions/snippet.rs | 4 ++-- crates/ide_completion/src/completions/unqualified_path.rs | 2 +- 6 files changed, 15 insertions(+), 14 deletions(-) (limited to 'crates/ide_completion/src/completions') diff --git a/crates/ide_completion/src/completions/dot.rs b/crates/ide_completion/src/completions/dot.rs index 22844c2ae..8ad57a069 100644 --- a/crates/ide_completion/src/completions/dot.rs +++ b/crates/ide_completion/src/completions/dot.rs @@ -33,7 +33,7 @@ fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.config.enable_self_on_the_fly { return; } - if !ctx.is_trivial_path || ctx.is_path_disallowed() { + if !ctx.is_trivial_path() || ctx.is_path_disallowed() { return; } ctx.scope.process_all_names(&mut |name, def| { diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index d72bf13d3..7bf47bf75 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -161,13 +161,13 @@ pub(crate) fn position_for_import<'a>( ) -> Option<&'a SyntaxNode> { Some(match import_candidate { Some(ImportCandidate::Path(_)) => ctx.name_ref_syntax.as_ref()?.syntax(), - Some(ImportCandidate::TraitAssocItem(_)) => ctx.path_qual.as_ref()?.syntax(), + Some(ImportCandidate::TraitAssocItem(_)) => ctx.path_qual()?.syntax(), Some(ImportCandidate::TraitMethod(_)) => ctx.dot_receiver()?.syntax(), None => ctx .name_ref_syntax .as_ref() .map(|name_ref| name_ref.syntax()) - .or_else(|| ctx.path_qual.as_ref().map(|path| path.syntax())) + .or_else(|| ctx.path_qual().map(|path| path.syntax())) .or_else(|| ctx.dot_receiver().map(|expr| expr.syntax()))?, }) } @@ -190,7 +190,7 @@ fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option "return $0;", (true, false) => "return;", (false, true) => "return $0", diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index de58ce1cd..c072de7b5 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -10,8 +10,8 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon if ctx.is_path_disallowed() || ctx.expects_item() { return; } - let path = match &ctx.path_qual { - Some(path) => path.clone(), + let path = match ctx.path_qual() { + Some(path) => path, None => return, }; diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs index 6e6a6eb92..59a338e7b 100644 --- a/crates/ide_completion/src/completions/snippet.rs +++ b/crates/ide_completion/src/completions/snippet.rs @@ -14,7 +14,7 @@ fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) } pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { - if !(ctx.is_trivial_path && ctx.function_def.is_some()) { + if !(ctx.is_trivial_path() && ctx.function_def.is_some()) { return; } let cap = match ctx.config.snippet_cap { @@ -22,7 +22,7 @@ pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte None => return, }; - if ctx.can_be_stmt { + if ctx.can_be_stmt() { snippet(ctx, cap, "pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc); snippet(ctx, cap, "ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc); } diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index bd955aa85..f321ed52b 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs @@ -5,7 +5,7 @@ use hir::ScopeDef; use crate::{CompletionContext, Completions}; pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { - if !ctx.is_trivial_path { + if !ctx.is_trivial_path() { return; } if ctx.is_path_disallowed() || ctx.expects_item() { -- cgit v1.2.3