@@ -102,32 +102,17 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
102
102
}
103
103
104
104
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) ?;
131
116
Some ( ( trigger, impl_def) )
132
117
}
133
118
0 commit comments