mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-05 16:11:01 +00:00
Don't allow nested completions
This commit is contained in:
parent
15ed114a49
commit
7c439355ce
1 changed files with 18 additions and 13 deletions
|
@ -48,23 +48,28 @@ use crate::{
|
||||||
|
|
||||||
pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
let mut tokens = ctx.token.ancestors();
|
let mut tokens = ctx.token.ancestors();
|
||||||
let trigger = tokens.find(|p| match p.kind() {
|
let completion_match = tokens
|
||||||
SyntaxKind::FN_DEF
|
|
||||||
| SyntaxKind::TYPE_ALIAS_DEF
|
|
||||||
| SyntaxKind::CONST_DEF
|
|
||||||
| SyntaxKind::NAME_REF
|
|
||||||
| SyntaxKind::BLOCK_EXPR => true,
|
|
||||||
_ => false,
|
|
||||||
});
|
|
||||||
|
|
||||||
let impl_def = tokens
|
|
||||||
.find(|p| match p.kind() {
|
.find(|p| match p.kind() {
|
||||||
SyntaxKind::IMPL_DEF => true,
|
SyntaxKind::FN_DEF
|
||||||
|
| SyntaxKind::TYPE_ALIAS_DEF
|
||||||
|
| SyntaxKind::CONST_DEF
|
||||||
|
| SyntaxKind::NAME_REF
|
||||||
|
| SyntaxKind::BLOCK_EXPR => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
})
|
})
|
||||||
.and_then(|n| ast::ImplDef::cast(n));
|
.and_then(|trigger| {
|
||||||
|
for p in tokens {
|
||||||
|
match p.kind() {
|
||||||
|
// No nested completions
|
||||||
|
SyntaxKind::FN_DEF | SyntaxKind::BLOCK => return None,
|
||||||
|
SyntaxKind::IMPL_DEF => return ast::ImplDef::cast(p).map(|p| (trigger, p)),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
});
|
||||||
|
|
||||||
if let (Some(trigger), Some(impl_def)) = (trigger, impl_def) {
|
if let Some((trigger, impl_def)) = completion_match {
|
||||||
match trigger.kind() {
|
match trigger.kind() {
|
||||||
SyntaxKind::NAME_REF => {
|
SyntaxKind::NAME_REF => {
|
||||||
get_missing_impl_items(&ctx.sema, &impl_def).iter().for_each(|item| match item {
|
get_missing_impl_items(&ctx.sema, &impl_def).iter().for_each(|item| match item {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue