Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/completions.rs')
| -rw-r--r-- | crates/ide-completion/src/completions.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/crates/ide-completion/src/completions.rs b/crates/ide-completion/src/completions.rs index 1bcbb3aaa6..b254e458eb 100644 --- a/crates/ide-completion/src/completions.rs +++ b/crates/ide-completion/src/completions.rs @@ -91,11 +91,31 @@ impl Completions { } pub(crate) fn add_nameref_keywords_with_colon(&mut self, ctx: &CompletionContext) { - ["self::", "super::", "crate::"].into_iter().for_each(|kw| self.add_keyword(ctx, kw)); + ["self::", "crate::"].into_iter().for_each(|kw| self.add_keyword(ctx, kw)); + + if ctx.depth_from_crate_root > 0 { + self.add_keyword(ctx, "super::"); + } } pub(crate) fn add_nameref_keywords(&mut self, ctx: &CompletionContext) { - ["self", "super", "crate"].into_iter().for_each(|kw| self.add_keyword(ctx, kw)); + ["self", "crate"].into_iter().for_each(|kw| self.add_keyword(ctx, kw)); + + if ctx.depth_from_crate_root > 0 { + self.add_keyword(ctx, "super"); + } + } + + pub(crate) fn add_super_keyword( + &mut self, + ctx: &CompletionContext, + super_chain_len: Option<usize>, + ) { + if let Some(len) = super_chain_len { + if len > 0 && len < ctx.depth_from_crate_root { + self.add_keyword(ctx, "super::"); + } + } } pub(crate) fn add_keyword_snippet_expr( |