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/render/builder_ext.rs | 12 +++++++----- crates/ide_completion/src/render/macro_.rs | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'crates/ide_completion/src/render') diff --git a/crates/ide_completion/src/render/builder_ext.rs b/crates/ide_completion/src/render/builder_ext.rs index 6d062b3b9..c54752d30 100644 --- a/crates/ide_completion/src/render/builder_ext.rs +++ b/crates/ide_completion/src/render/builder_ext.rs @@ -2,7 +2,7 @@ use itertools::Itertools; -use crate::{item::Builder, CompletionContext}; +use crate::{context::CallKind, item::Builder, patterns::ImmediateLocation, CompletionContext}; #[derive(Debug)] pub(super) enum Params { @@ -32,10 +32,12 @@ impl Builder { cov_mark::hit!(no_parens_in_use_item); return false; } - if ctx.is_pattern_call { - return false; - } - if ctx.is_call { + if matches!(ctx.path_call_kind(), Some(CallKind::Expr) | Some(CallKind::Pat)) + | matches!( + ctx.completion_location, + Some(ImmediateLocation::MethodCall { has_parens: true, .. }) + ) + { return false; } diff --git a/crates/ide_completion/src/render/macro_.rs b/crates/ide_completion/src/render/macro_.rs index 0dfba8acc..429d937c8 100644 --- a/crates/ide_completion/src/render/macro_.rs +++ b/crates/ide_completion/src/render/macro_.rs @@ -5,6 +5,7 @@ use ide_db::SymbolKind; use syntax::display::macro_label; use crate::{ + context::CallKind, item::{CompletionItem, CompletionKind, ImportEdit}, render::RenderContext, }; @@ -68,7 +69,8 @@ impl<'a> MacroRender<'a> { } fn needs_bang(&self) -> bool { - self.ctx.completion.use_item_syntax.is_none() && !self.ctx.completion.is_macro_call + self.ctx.completion.use_item_syntax.is_none() + && !matches!(self.ctx.completion.path_call_kind(), Some(CallKind::Mac)) } fn label(&self) -> String { -- cgit v1.2.3