mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
internal: completion: split out more PathKinds from ImmediateLocation
This commit is contained in:
parent
49b0970970
commit
ae0c7268f7
10 changed files with 206 additions and 160 deletions
|
@ -4,7 +4,7 @@ use either::Either;
|
|||
use itertools::Itertools;
|
||||
use syntax::ast::{self, HasName};
|
||||
|
||||
use crate::{context::CallKind, item::Builder, patterns::ImmediateLocation, CompletionContext};
|
||||
use crate::{context::PathKind, item::Builder, patterns::ImmediateLocation, CompletionContext};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(super) enum Params {
|
||||
|
@ -30,11 +30,11 @@ impl Builder {
|
|||
if !ctx.config.add_call_parenthesis {
|
||||
return false;
|
||||
}
|
||||
if ctx.in_use_tree() {
|
||||
if let Some(PathKind::Use) = ctx.path_kind() {
|
||||
cov_mark::hit!(no_parens_in_use_item);
|
||||
return false;
|
||||
}
|
||||
if matches!(ctx.path_call_kind(), Some(CallKind::Expr | CallKind::Pat))
|
||||
if matches!(ctx.path_kind(), Some(PathKind::Expr | PathKind::Pat) if ctx.path_is_call())
|
||||
| matches!(
|
||||
ctx.completion_location,
|
||||
Some(ImmediateLocation::MethodCall { has_parens: true, .. })
|
||||
|
|
|
@ -9,7 +9,7 @@ use syntax::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
context::CallKind,
|
||||
context::PathKind,
|
||||
item::{CompletionItem, ImportEdit},
|
||||
render::RenderContext,
|
||||
};
|
||||
|
@ -67,9 +67,8 @@ impl<'a> MacroRender<'a> {
|
|||
}
|
||||
|
||||
let needs_bang = self.macro_.is_fn_like()
|
||||
&& !(self.ctx.completion.in_use_tree()
|
||||
|| matches!(self.ctx.completion.path_call_kind(), Some(CallKind::Mac)));
|
||||
let has_parens = self.ctx.completion.path_call_kind().is_some();
|
||||
&& !matches!(self.ctx.completion.path_kind(), Some(PathKind::Mac | PathKind::Use));
|
||||
let has_parens = self.ctx.completion.path_is_call();
|
||||
|
||||
match self.ctx.snippet_cap() {
|
||||
Some(cap) if needs_bang && !has_parens => {
|
||||
|
@ -92,8 +91,7 @@ impl<'a> MacroRender<'a> {
|
|||
}
|
||||
|
||||
fn needs_bang(&self) -> bool {
|
||||
!self.ctx.completion.in_use_tree()
|
||||
&& !matches!(self.ctx.completion.path_call_kind(), Some(CallKind::Mac))
|
||||
!matches!(self.ctx.completion.path_kind(), Some(PathKind::Mac | PathKind::Use))
|
||||
}
|
||||
|
||||
fn label(&self) -> SmolStr {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue