diff options
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r-- | crates/ra_ide/src/completion/complete_trait_impl.rs | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index ba7d43f1e..2bf654a57 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs | |||
@@ -102,32 +102,17 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext | |||
102 | } | 102 | } |
103 | 103 | ||
104 | fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { | 104 | fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { |
105 | let (trigger_idx, trigger) = | 105 | let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { |
106 | ctx.token.ancestors().enumerate().find(|(_idx, p)| match p.kind() { | 106 | SyntaxKind::FN_DEF |
107 | SyntaxKind::FN_DEF | 107 | | SyntaxKind::TYPE_ALIAS_DEF |
108 | | SyntaxKind::TYPE_ALIAS_DEF | 108 | | SyntaxKind::CONST_DEF |
109 | | SyntaxKind::CONST_DEF | 109 | | SyntaxKind::BLOCK_EXPR => Some((p, 2)), |
110 | | SyntaxKind::NAME_REF | 110 | SyntaxKind::NAME_REF => Some((p, 5)), |
111 | | SyntaxKind::BLOCK_EXPR => true, | 111 | _ => None, |
112 | _ => false, | 112 | })?; |
113 | })?; | 113 | let impl_def = (0..impl_def_offset - 1) |
114 | let (impl_def_idx, impl_def) = | 114 | .try_fold(trigger.parent()?, |t, _| t.parent()) |
115 | ctx.token.ancestors().enumerate().skip(trigger_idx + 1).find_map(|(idx, p)| { | 115 | .and_then(ast::ImplDef::cast)?; |
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(()))?; | ||
131 | Some((trigger, impl_def)) | 116 | Some((trigger, impl_def)) |
132 | } | 117 | } |
133 | 118 | ||