Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide-completion/src/completions/expr.rs30
-rw-r--r--crates/ide-completion/src/completions/field.rs25
-rw-r--r--crates/ide-completion/src/completions/item_list.rs50
-rw-r--r--crates/ide-completion/src/lib.rs17
4 files changed, 47 insertions, 75 deletions
diff --git a/crates/ide-completion/src/completions/expr.rs b/crates/ide-completion/src/completions/expr.rs
index afc929d68d..6152ccb711 100644
--- a/crates/ide-completion/src/completions/expr.rs
+++ b/crates/ide-completion/src/completions/expr.rs
@@ -4,14 +4,14 @@ use hir::ScopeDef;
use ide_db::FxHashSet;
use crate::{
- context::{NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified},
+ context::{PathCompletionCtx, PathKind, Qualified},
CompletionContext, Completions,
};
pub(crate) fn complete_expr_path(
acc: &mut Completions,
ctx: &CompletionContext,
- name_ref_ctx: &NameRefContext,
+ path_ctx: &PathCompletionCtx,
) {
let _p = profile::span("complete_expr_path");
@@ -23,22 +23,18 @@ pub(crate) fn complete_expr_path(
after_if_expr,
wants_mut_token,
in_condition,
- ) = match name_ref_ctx {
- &NameRefContext {
+ ) = match path_ctx {
+ &PathCompletionCtx {
kind:
- Some(NameRefKind::Path(PathCompletionCtx {
- kind:
- PathKind::Expr {
- in_block_expr,
- in_loop_body,
- after_if_expr,
- in_condition,
- ref ref_expr_parent,
- ref is_func_update,
- },
- ref qualified,
- ..
- })),
+ PathKind::Expr {
+ in_block_expr,
+ in_loop_body,
+ after_if_expr,
+ in_condition,
+ ref ref_expr_parent,
+ ref is_func_update,
+ },
+ ref qualified,
..
} if ctx.qualifier_ctx.none() => (
qualified,
diff --git a/crates/ide-completion/src/completions/field.rs b/crates/ide-completion/src/completions/field.rs
index 93263f61cf..6d346c5fd4 100644
--- a/crates/ide-completion/src/completions/field.rs
+++ b/crates/ide-completion/src/completions/field.rs
@@ -1,29 +1,22 @@
//! Completion of field list position.
use crate::{
- context::{
- NameContext, NameKind, NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified,
- TypeLocation,
- },
+ context::{NameContext, NameKind, PathCompletionCtx, PathKind, Qualified, TypeLocation},
CompletionContext, Completions,
};
pub(crate) fn complete_field_list_tuple_variant(
acc: &mut Completions,
ctx: &CompletionContext,
- name_ref_ctx: &NameRefContext,
+ path_ctx: &PathCompletionCtx,
) {
- match name_ref_ctx {
- NameRefContext {
- kind:
- Some(NameRefKind::Path(PathCompletionCtx {
- has_macro_bang: false,
- qualified: Qualified::No,
- parent: None,
- kind: PathKind::Type { location: TypeLocation::TupleField },
- has_type_args: false,
- ..
- })),
+ match path_ctx {
+ PathCompletionCtx {
+ has_macro_bang: false,
+ qualified: Qualified::No,
+ parent: None,
+ kind: PathKind::Type { location: TypeLocation::TupleField },
+ has_type_args: false,
..
} => {
if ctx.qualifier_ctx.vis_node.is_none() {
diff --git a/crates/ide-completion/src/completions/item_list.rs b/crates/ide-completion/src/completions/item_list.rs
index e613f2d25b..f4402a3f87 100644
--- a/crates/ide-completion/src/completions/item_list.rs
+++ b/crates/ide-completion/src/completions/item_list.rs
@@ -2,7 +2,7 @@
use crate::{
completions::module_or_fn_macro,
- context::{ItemListKind, NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified},
+ context::{ItemListKind, PathCompletionCtx, PathKind, Qualified},
CompletionContext, Completions,
};
@@ -11,45 +11,25 @@ pub(crate) mod trait_impl;
pub(crate) fn complete_item_list(
acc: &mut Completions,
ctx: &CompletionContext,
- name_ref_ctx: &NameRefContext,
+ path_ctx: &PathCompletionCtx,
) {
let _p = profile::span("complete_item_list");
-
- let (qualified, item_list_kind, is_trivial_path) = match name_ref_ctx {
- NameRefContext {
- 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()),
+ let qualified = match path_ctx {
+ PathCompletionCtx { kind: PathKind::Item { kind }, qualified, .. } => {
+ if path_ctx.is_trivial_path() {
+ add_keywords(acc, ctx, Some(kind));
+ }
+ qualified
+ }
+ PathCompletionCtx { kind: PathKind::Expr { in_block_expr: true, .. }, .. }
+ if path_ctx.is_trivial_path() =>
+ {
+ add_keywords(acc, ctx, None);
+ return;
+ }
_ => return,
};
- if matches!(item_list_kind, Some(ItemListKind::TraitImpl)) {
- trait_impl::complete_trait_impl_name_ref(acc, ctx, name_ref_ctx);
- }
-
- if is_trivial_path {
- add_keywords(acc, ctx, item_list_kind);
- }
-
- if item_list_kind.is_none() {
- // this is already handled by expression
- return;
- }
-
match qualified {
Qualified::With {
resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),
diff --git a/crates/ide-completion/src/lib.rs b/crates/ide-completion/src/lib.rs
index 9f548c888a..b5022dab93 100644
--- a/crates/ide-completion/src/lib.rs
+++ b/crates/ide-completion/src/lib.rs
@@ -171,22 +171,25 @@ pub fn completions(
completions::item_list::trait_impl::complete_trait_impl_name(acc, ctx, name_ctx);
completions::mod_::complete_mod(acc, ctx, name_ctx);
}
- IdentContext::NameRef(name_ref_ctx @ NameRefContext { kind, .. }) => {
- completions::expr::complete_expr_path(acc, ctx, name_ref_ctx);
- completions::field::complete_field_list_tuple_variant(acc, ctx, name_ref_ctx);
- completions::item_list::complete_item_list(acc, ctx, name_ref_ctx);
- completions::use_::complete_use_tree(acc, ctx, name_ref_ctx);
+ IdentContext::NameRef(name_ctx @ NameRefContext { kind, .. }) => {
+ completions::item_list::trait_impl::complete_trait_impl_name_ref(
+ acc, ctx, name_ctx,
+ );
+ completions::use_::complete_use_tree(acc, ctx, name_ctx);
match kind {
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_derive(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::r#type::complete_inferred_type(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_item_snippet(acc, ctx, path_ctx);
completions::vis::complete_vis_path(acc, ctx, path_ctx);