Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/lib.rs')
-rw-r--r--crates/ide-completion/src/lib.rs129
1 files changed, 77 insertions, 52 deletions
diff --git a/crates/ide-completion/src/lib.rs b/crates/ide-completion/src/lib.rs
index 27fe66e385..5e9923eb0f 100644
--- a/crates/ide-completion/src/lib.rs
+++ b/crates/ide-completion/src/lib.rs
@@ -24,7 +24,9 @@ use text_edit::TextEdit;
use crate::{
completions::Completions,
- context::{CompletionContext, IdentContext, NameKind, NameRefContext, NameRefKind},
+ context::{
+ CompletionContext, IdentContext, NameContext, NameKind, NameRefContext, NameRefKind,
+ },
};
pub use crate::{
@@ -164,63 +166,86 @@ pub fn completions(
let acc = &mut completions;
match &ctx.ident_ctx {
- IdentContext::Name(name_ctx) => {
- completions::field::complete_field_list_record_variant(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);
- if let NameKind::IdentPat(pattern_ctx) = &name_ctx.kind {
+ IdentContext::Name(NameContext { name, kind }) => match kind {
+ NameKind::Const => {
+ completions::item_list::trait_impl::complete_trait_impl_const(acc, ctx, name);
+ }
+ NameKind::Function => {
+ completions::item_list::trait_impl::complete_trait_impl_fn(acc, ctx, name);
+ }
+ NameKind::IdentPat(pattern_ctx) => {
completions::flyimport::import_on_the_fly_pat(acc, ctx, pattern_ctx);
completions::fn_param::complete_fn_param(acc, ctx, pattern_ctx);
completions::pattern::complete_pattern(acc, ctx, pattern_ctx);
completions::record::complete_record_pattern_fields(acc, ctx, pattern_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 {
- NameRefKind::Path(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);
- }
- NameRefKind::DotAccess(dot_access) => {
- completions::flyimport::import_on_the_fly_dot(acc, ctx, dot_access);
- completions::dot::complete_dot(acc, ctx, dot_access);
- completions::postfix::complete_postfix(acc, ctx, dot_access);
- }
- NameRefKind::Keyword(item) => {
- completions::keyword::complete_special_keywords(acc, ctx, item);
- }
- NameRefKind::RecordExpr(record_expr) => {
- completions::record::complete_record_expr_fields_record_expr(
- acc,
- ctx,
- record_expr,
- );
- }
- NameRefKind::Pattern(pattern_ctx) => {
- completions::flyimport::import_on_the_fly_pat(acc, ctx, pattern_ctx);
- completions::fn_param::complete_fn_param(acc, ctx, pattern_ctx);
- completions::pattern::complete_pattern(acc, ctx, pattern_ctx);
- completions::record::complete_record_pattern_fields(acc, ctx, pattern_ctx);
- }
+ NameKind::Module(mod_under_caret) => {
+ completions::mod_::complete_mod(acc, ctx, mod_under_caret);
}
- }
+ NameKind::TypeAlias => {
+ completions::item_list::trait_impl::complete_trait_impl_type_alias(
+ acc, ctx, name,
+ );
+ }
+ NameKind::RecordField => {
+ completions::field::complete_field_list_record_variant(acc, ctx);
+ }
+ NameKind::ConstParam
+ | NameKind::Enum
+ | NameKind::MacroDef
+ | NameKind::MacroRules
+ | NameKind::Rename
+ | NameKind::SelfParam
+ | NameKind::Static
+ | NameKind::Struct
+ | NameKind::Trait
+ | NameKind::TypeParam
+ | NameKind::Union
+ | NameKind::Variant => (),
+ },
+ IdentContext::NameRef(NameRefContext { kind, nameref }) => match kind {
+ NameRefKind::Path(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::item_list::trait_impl::complete_trait_impl_name_ref(
+ acc, ctx, path_ctx, nameref,
+ );
+ 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::use_::complete_use_tree(acc, ctx, path_ctx, nameref);
+ completions::vis::complete_vis_path(acc, ctx, path_ctx);
+ }
+ NameRefKind::DotAccess(dot_access) => {
+ completions::flyimport::import_on_the_fly_dot(acc, ctx, dot_access);
+ completions::dot::complete_dot(acc, ctx, dot_access);
+ completions::postfix::complete_postfix(acc, ctx, dot_access);
+ }
+ NameRefKind::Keyword(item) => {
+ completions::keyword::complete_special_keywords(acc, ctx, item);
+ }
+ NameRefKind::RecordExpr(record_expr) => {
+ completions::record::complete_record_expr_fields_record_expr(
+ acc,
+ ctx,
+ record_expr,
+ );
+ }
+ NameRefKind::Pattern(pattern_ctx) => {
+ completions::flyimport::import_on_the_fly_pat(acc, ctx, pattern_ctx);
+ completions::fn_param::complete_fn_param(acc, ctx, pattern_ctx);
+ completions::pattern::complete_pattern(acc, ctx, pattern_ctx);
+ completions::record::complete_record_pattern_fields(acc, ctx, pattern_ctx);
+ }
+ },
IdentContext::Lifetime(lifetime_ctx) => {
completions::lifetime::complete_label(acc, ctx, lifetime_ctx);
completions::lifetime::complete_lifetime(acc, ctx, lifetime_ctx);