mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-04 01:08:47 +00:00
commit
12dd81092e
4 changed files with 47 additions and 75 deletions
|
@ -4,14 +4,14 @@ use hir::ScopeDef;
|
||||||
use ide_db::FxHashSet;
|
use ide_db::FxHashSet;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
context::{NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified},
|
context::{PathCompletionCtx, PathKind, Qualified},
|
||||||
CompletionContext, Completions,
|
CompletionContext, Completions,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn complete_expr_path(
|
pub(crate) fn complete_expr_path(
|
||||||
acc: &mut Completions,
|
acc: &mut Completions,
|
||||||
ctx: &CompletionContext,
|
ctx: &CompletionContext,
|
||||||
name_ref_ctx: &NameRefContext,
|
path_ctx: &PathCompletionCtx,
|
||||||
) {
|
) {
|
||||||
let _p = profile::span("complete_expr_path");
|
let _p = profile::span("complete_expr_path");
|
||||||
|
|
||||||
|
@ -23,10 +23,8 @@ pub(crate) fn complete_expr_path(
|
||||||
after_if_expr,
|
after_if_expr,
|
||||||
wants_mut_token,
|
wants_mut_token,
|
||||||
in_condition,
|
in_condition,
|
||||||
) = match name_ref_ctx {
|
) = match path_ctx {
|
||||||
&NameRefContext {
|
&PathCompletionCtx {
|
||||||
kind:
|
|
||||||
Some(NameRefKind::Path(PathCompletionCtx {
|
|
||||||
kind:
|
kind:
|
||||||
PathKind::Expr {
|
PathKind::Expr {
|
||||||
in_block_expr,
|
in_block_expr,
|
||||||
|
@ -38,8 +36,6 @@ pub(crate) fn complete_expr_path(
|
||||||
},
|
},
|
||||||
ref qualified,
|
ref qualified,
|
||||||
..
|
..
|
||||||
})),
|
|
||||||
..
|
|
||||||
} if ctx.qualifier_ctx.none() => (
|
} if ctx.qualifier_ctx.none() => (
|
||||||
qualified,
|
qualified,
|
||||||
in_block_expr,
|
in_block_expr,
|
||||||
|
|
|
@ -1,30 +1,23 @@
|
||||||
//! Completion of field list position.
|
//! Completion of field list position.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
context::{
|
context::{NameContext, NameKind, PathCompletionCtx, PathKind, Qualified, TypeLocation},
|
||||||
NameContext, NameKind, NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified,
|
|
||||||
TypeLocation,
|
|
||||||
},
|
|
||||||
CompletionContext, Completions,
|
CompletionContext, Completions,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn complete_field_list_tuple_variant(
|
pub(crate) fn complete_field_list_tuple_variant(
|
||||||
acc: &mut Completions,
|
acc: &mut Completions,
|
||||||
ctx: &CompletionContext,
|
ctx: &CompletionContext,
|
||||||
name_ref_ctx: &NameRefContext,
|
path_ctx: &PathCompletionCtx,
|
||||||
) {
|
) {
|
||||||
match name_ref_ctx {
|
match path_ctx {
|
||||||
NameRefContext {
|
PathCompletionCtx {
|
||||||
kind:
|
|
||||||
Some(NameRefKind::Path(PathCompletionCtx {
|
|
||||||
has_macro_bang: false,
|
has_macro_bang: false,
|
||||||
qualified: Qualified::No,
|
qualified: Qualified::No,
|
||||||
parent: None,
|
parent: None,
|
||||||
kind: PathKind::Type { location: TypeLocation::TupleField },
|
kind: PathKind::Type { location: TypeLocation::TupleField },
|
||||||
has_type_args: false,
|
has_type_args: false,
|
||||||
..
|
..
|
||||||
})),
|
|
||||||
..
|
|
||||||
} => {
|
} => {
|
||||||
if ctx.qualifier_ctx.vis_node.is_none() {
|
if ctx.qualifier_ctx.vis_node.is_none() {
|
||||||
let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet);
|
let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
completions::module_or_fn_macro,
|
completions::module_or_fn_macro,
|
||||||
context::{ItemListKind, NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified},
|
context::{ItemListKind, PathCompletionCtx, PathKind, Qualified},
|
||||||
CompletionContext, Completions,
|
CompletionContext, Completions,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,44 +11,24 @@ pub(crate) mod trait_impl;
|
||||||
pub(crate) fn complete_item_list(
|
pub(crate) fn complete_item_list(
|
||||||
acc: &mut Completions,
|
acc: &mut Completions,
|
||||||
ctx: &CompletionContext,
|
ctx: &CompletionContext,
|
||||||
name_ref_ctx: &NameRefContext,
|
path_ctx: &PathCompletionCtx,
|
||||||
) {
|
) {
|
||||||
let _p = profile::span("complete_item_list");
|
let _p = profile::span("complete_item_list");
|
||||||
|
let qualified = match path_ctx {
|
||||||
let (qualified, item_list_kind, is_trivial_path) = match name_ref_ctx {
|
PathCompletionCtx { kind: PathKind::Item { kind }, qualified, .. } => {
|
||||||
NameRefContext {
|
if path_ctx.is_trivial_path() {
|
||||||
kind:
|
add_keywords(acc, ctx, Some(kind));
|
||||||
Some(NameRefKind::Path(
|
|
||||||
ctx @ PathCompletionCtx { kind: PathKind::Item { kind }, qualified, .. },
|
|
||||||
)),
|
|
||||||
..
|
|
||||||
} => (qualified, Some(kind), ctx.is_trivial_path()),
|
|
||||||
NameRefContext {
|
|
||||||
kind:
|
|
||||||
Some(NameRefKind::Path(
|
|
||||||
ctx @ PathCompletionCtx {
|
|
||||||
kind: PathKind::Expr { in_block_expr: true, .. },
|
|
||||||
qualified,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
..
|
|
||||||
} => (qualified, None, ctx.is_trivial_path()),
|
|
||||||
_ => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
if matches!(item_list_kind, Some(ItemListKind::TraitImpl)) {
|
|
||||||
trait_impl::complete_trait_impl_name_ref(acc, ctx, name_ref_ctx);
|
|
||||||
}
|
}
|
||||||
|
qualified
|
||||||
if is_trivial_path {
|
|
||||||
add_keywords(acc, ctx, item_list_kind);
|
|
||||||
}
|
}
|
||||||
|
PathCompletionCtx { kind: PathKind::Expr { in_block_expr: true, .. }, .. }
|
||||||
if item_list_kind.is_none() {
|
if path_ctx.is_trivial_path() =>
|
||||||
// this is already handled by expression
|
{
|
||||||
|
add_keywords(acc, ctx, None);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_ => return,
|
||||||
|
};
|
||||||
|
|
||||||
match qualified {
|
match qualified {
|
||||||
Qualified::With {
|
Qualified::With {
|
||||||
|
|
|
@ -171,22 +171,25 @@ pub fn completions(
|
||||||
completions::item_list::trait_impl::complete_trait_impl_name(acc, ctx, name_ctx);
|
completions::item_list::trait_impl::complete_trait_impl_name(acc, ctx, name_ctx);
|
||||||
completions::mod_::complete_mod(acc, ctx, name_ctx);
|
completions::mod_::complete_mod(acc, ctx, name_ctx);
|
||||||
}
|
}
|
||||||
IdentContext::NameRef(name_ref_ctx @ NameRefContext { kind, .. }) => {
|
IdentContext::NameRef(name_ctx @ NameRefContext { kind, .. }) => {
|
||||||
completions::expr::complete_expr_path(acc, ctx, name_ref_ctx);
|
completions::item_list::trait_impl::complete_trait_impl_name_ref(
|
||||||
completions::field::complete_field_list_tuple_variant(acc, ctx, name_ref_ctx);
|
acc, ctx, name_ctx,
|
||||||
completions::item_list::complete_item_list(acc, ctx, name_ref_ctx);
|
);
|
||||||
completions::use_::complete_use_tree(acc, ctx, name_ref_ctx);
|
completions::use_::complete_use_tree(acc, ctx, name_ctx);
|
||||||
|
|
||||||
match kind {
|
match kind {
|
||||||
Some(NameRefKind::Path(path_ctx)) => {
|
Some(NameRefKind::Path(path_ctx)) => {
|
||||||
completions::flyimport::import_on_the_fly_path(acc, ctx, path_ctx);
|
|
||||||
completions::record::complete_record_expr_func_update(acc, ctx, path_ctx);
|
|
||||||
completions::attribute::complete_attribute(acc, ctx, path_ctx);
|
completions::attribute::complete_attribute(acc, ctx, path_ctx);
|
||||||
completions::attribute::complete_derive(acc, ctx, path_ctx);
|
completions::attribute::complete_derive(acc, ctx, path_ctx);
|
||||||
completions::dot::complete_undotted_self(acc, ctx, path_ctx);
|
completions::dot::complete_undotted_self(acc, ctx, path_ctx);
|
||||||
|
completions::expr::complete_expr_path(acc, ctx, path_ctx);
|
||||||
|
completions::field::complete_field_list_tuple_variant(acc, ctx, path_ctx);
|
||||||
|
completions::flyimport::import_on_the_fly_path(acc, ctx, path_ctx);
|
||||||
|
completions::item_list::complete_item_list(acc, ctx, path_ctx);
|
||||||
completions::pattern::pattern_path_completion(acc, ctx, path_ctx);
|
completions::pattern::pattern_path_completion(acc, ctx, path_ctx);
|
||||||
completions::r#type::complete_inferred_type(acc, ctx, path_ctx);
|
completions::r#type::complete_inferred_type(acc, ctx, path_ctx);
|
||||||
completions::r#type::complete_type_path(acc, ctx, path_ctx);
|
completions::r#type::complete_type_path(acc, ctx, path_ctx);
|
||||||
|
completions::record::complete_record_expr_func_update(acc, ctx, path_ctx);
|
||||||
completions::snippet::complete_expr_snippet(acc, ctx, path_ctx);
|
completions::snippet::complete_expr_snippet(acc, ctx, path_ctx);
|
||||||
completions::snippet::complete_item_snippet(acc, ctx, path_ctx);
|
completions::snippet::complete_item_snippet(acc, ctx, path_ctx);
|
||||||
completions::vis::complete_vis_path(acc, ctx, path_ctx);
|
completions::vis::complete_vis_path(acc, ctx, path_ctx);
|
||||||
|
|
Loading…
Reference in a new issue