Skip to content

Commit f67e6a8

Browse files
committed
Switch to explicit offsets for impl_def
Blacklists are prone to more errors
1 parent 9138d39 commit f67e6a8

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

crates/ra_ide/src/completion/complete_trait_impl.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -102,32 +102,17 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
102102
}
103103

104104
fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> {
105-
let (trigger_idx, trigger) =
106-
ctx.token.ancestors().enumerate().find(|(_idx, p)| match p.kind() {
107-
SyntaxKind::FN_DEF
108-
| SyntaxKind::TYPE_ALIAS_DEF
109-
| SyntaxKind::CONST_DEF
110-
| SyntaxKind::NAME_REF
111-
| SyntaxKind::BLOCK_EXPR => true,
112-
_ => false,
113-
})?;
114-
let (impl_def_idx, impl_def) =
115-
ctx.token.ancestors().enumerate().skip(trigger_idx + 1).find_map(|(idx, p)| {
116-
match p.kind() {
117-
SyntaxKind::IMPL_DEF => ast::ImplDef::cast(p).map(|p| (idx, p)),
118-
_ => None,
119-
}
120-
})?;
121-
let _is_nested = ctx
122-
.token
123-
.ancestors()
124-
.skip(trigger_idx + 1)
125-
.take(impl_def_idx - trigger_idx - 1)
126-
.find_map(|p| match p.kind() {
127-
SyntaxKind::FN_DEF | SyntaxKind::BLOCK => Some(()),
128-
_ => None,
129-
})
130-
.xor(Some(()))?;
105+
let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() {
106+
SyntaxKind::FN_DEF
107+
| SyntaxKind::TYPE_ALIAS_DEF
108+
| SyntaxKind::CONST_DEF
109+
| SyntaxKind::BLOCK_EXPR => Some((p, 2)),
110+
SyntaxKind::NAME_REF => Some((p, 5)),
111+
_ => None,
112+
})?;
113+
let impl_def = (0..impl_def_offset - 1)
114+
.try_fold(trigger.parent()?, |t, _| t.parent())
115+
.and_then(ast::ImplDef::cast)?;
131116
Some((trigger, impl_def))
132117
}
133118

0 commit comments

Comments
 (0)