Simplify CompletionContext by introducing a path CallKind enum

This commit is contained in:
Lukas Wirth
2021-06-06 20:02:26 +02:00
parent ad9234fef2
commit e475bcdcc6
6 changed files with 49 additions and 32 deletions

View File

@@ -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;
}

View File

@@ -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 {