Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/completions/pattern.rs')
-rw-r--r--crates/ide-completion/src/completions/pattern.rs34
1 files changed, 13 insertions, 21 deletions
diff --git a/crates/ide-completion/src/completions/pattern.rs b/crates/ide-completion/src/completions/pattern.rs
index b2630798bb..1ecae1c484 100644
--- a/crates/ide-completion/src/completions/pattern.rs
+++ b/crates/ide-completion/src/completions/pattern.rs
@@ -5,22 +5,16 @@ use ide_db::FxHashSet;
use syntax::ast::Pat;
use crate::{
- context::{PathCompletionCtx, PatternRefutability, Qualified},
+ context::{PathCompletionCtx, PathKind, PatternContext, PatternRefutability, Qualified},
CompletionContext, Completions,
};
/// Completes constants and paths in unqualified patterns.
-pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
- let patctx = match &ctx.pattern_ctx {
- Some(ctx) => ctx,
- _ => return,
- };
-
- if let Some(path_ctx) = ctx.path_context() {
- pattern_path_completion(acc, ctx, path_ctx);
- return;
- }
-
+pub(crate) fn complete_pattern(
+ acc: &mut Completions,
+ ctx: &CompletionContext,
+ patctx: &PatternContext,
+) {
match patctx.parent_pat.as_ref() {
Some(Pat::RangePat(_) | Pat::BoxPat(_)) => (),
Some(Pat::RefPat(r)) => {
@@ -108,22 +102,20 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
});
}
-fn pattern_path_completion(
+pub(crate) fn pattern_path_completion(
acc: &mut Completions,
ctx: &CompletionContext,
- PathCompletionCtx { qualified, .. }: &PathCompletionCtx,
+ PathCompletionCtx { qualified, kind, .. }: &PathCompletionCtx,
) {
+ if !matches!(kind, PathKind::Pat) {
+ return;
+ }
match qualified {
- Qualified::With { resolution, is_super_chain, .. } => {
+ Qualified::With { resolution: Some(resolution), is_super_chain, .. } => {
if *is_super_chain {
acc.add_keyword(ctx, "super::");
}
- let resolution = match resolution {
- Some(it) => it,
- None => return,
- };
-
match resolution {
hir::PathResolution::Def(hir::ModuleDef::Module(module)) => {
let module_scope = module.scope(ctx.db, Some(ctx.module));
@@ -208,6 +200,6 @@ fn pattern_path_completion(
acc.add_nameref_keywords_with_colon(ctx);
}
- Qualified::Infer => {}
+ Qualified::Infer | Qualified::With { .. } => {}
}
}