Introduce NameRefContext

This commit is contained in:
Lukas Wirth 2022-05-07 13:46:43 +02:00
parent 1dc83f5a90
commit 6a045c7029
20 changed files with 145 additions and 106 deletions

View file

@ -7,9 +7,8 @@ use stdx::{format_to, to_lower_snake_case};
use syntax::SmolStr;
use crate::{
context::{CompletionContext, PathCompletionCtx, PathKind},
context::{CompletionContext, DotAccess, NameRefContext, PathCompletionCtx, PathKind},
item::{Builder, CompletionItem, CompletionItemKind, CompletionRelevance},
patterns::ImmediateLocation,
render::{compute_exact_name_match, compute_ref_match, compute_type_match, RenderContext},
};
@ -196,7 +195,7 @@ fn should_add_parens(ctx: &CompletionContext) -> bool {
return false;
}
match ctx.path_context {
match ctx.path_context() {
Some(PathCompletionCtx { kind: PathKind::Expr { .. }, has_call_parens: true, .. }) => {
return false
}
@ -208,8 +207,8 @@ fn should_add_parens(ctx: &CompletionContext) -> bool {
};
if matches!(
ctx.completion_location,
Some(ImmediateLocation::MethodCall { has_parens: true, .. })
ctx.nameref_ctx,
Some(NameRefContext { dot_access: Some(DotAccess::Method { has_parens: true, .. }), .. })
) {
return false;
}

View file

@ -52,7 +52,7 @@ fn render(
let db = completion.db;
let kind = thing.kind(db);
let has_call_parens =
matches!(completion.path_context, Some(PathCompletionCtx { has_call_parens: true, .. }));
matches!(completion.path_context(), Some(PathCompletionCtx { has_call_parens: true, .. }));
let fields = thing.fields(completion)?;
let (qualified_name, short_qualified_name, qualified) = match path {

View file

@ -33,8 +33,8 @@ fn render(
let is_fn_like = macro_.is_fn_like(completion.db);
let (bra, ket) = if is_fn_like { guess_macro_braces(&name, docs_str) } else { ("", "") };
let needs_bang = match completion.path_context {
Some(PathCompletionCtx { kind, has_macro_bang, .. }) => {
let needs_bang = match completion.path_context() {
Some(&PathCompletionCtx { kind, has_macro_bang, .. }) => {
is_fn_like && kind != PathKind::Use && !has_macro_bang
}
_ => is_fn_like,

View file

@ -78,7 +78,7 @@ fn render_pat(
fields_omitted: bool,
) -> Option<String> {
let has_call_parens = matches!(
ctx.completion.path_context,
ctx.completion.path_context(),
Some(PathCompletionCtx { has_call_parens: true, .. })
);
let mut pat = match kind {