@@ -185,6 +185,8 @@ pub(super) struct NameRefContext {
185
185
// FIXME: these fields are actually disjoint -> enum
186
186
pub ( super ) dot_access : Option < DotAccess > ,
187
187
pub ( super ) path_ctx : Option < PathCompletionCtx > ,
188
+ /// Position where we are only interested in keyword completions
189
+ pub ( super ) keyword : Option < ast:: Item > ,
188
190
/// The record expression this nameref is a field of
189
191
pub ( super ) record_expr : Option < ( ast:: RecordExpr , bool ) > ,
190
192
}
@@ -343,21 +345,6 @@ impl<'a> CompletionContext<'a> {
343
345
matches ! ( self . completion_location, Some ( ImmediateLocation :: RefExpr ) )
344
346
}
345
347
346
- /// Whether the cursor is right after a trait or impl header.
347
- /// trait Foo ident$0
348
- // FIXME: This probably shouldn't exist
349
- pub ( crate ) fn has_unfinished_impl_or_trait_prev_sibling ( & self ) -> bool {
350
- matches ! (
351
- self . prev_sibling,
352
- Some ( ImmediatePrevSibling :: ImplDefType | ImmediatePrevSibling :: TraitDefName )
353
- )
354
- }
355
-
356
- // FIXME: This probably shouldn't exist
357
- pub ( crate ) fn has_impl_prev_sibling ( & self ) -> bool {
358
- matches ! ( self . prev_sibling, Some ( ImmediatePrevSibling :: ImplDefType ) )
359
- }
360
-
361
348
pub ( crate ) fn after_if ( & self ) -> bool {
362
349
matches ! ( self . prev_sibling, Some ( ImmediatePrevSibling :: IfExpr ) )
363
350
}
@@ -1092,8 +1079,13 @@ impl<'a> CompletionContext<'a> {
1092
1079
) -> ( NameRefContext , Option < PatternContext > ) {
1093
1080
let nameref = find_node_at_offset ( & original_file, name_ref. syntax ( ) . text_range ( ) . start ( ) ) ;
1094
1081
1095
- let mut nameref_ctx =
1096
- NameRefContext { dot_access : None , path_ctx : None , nameref, record_expr : None } ;
1082
+ let mut nameref_ctx = NameRefContext {
1083
+ dot_access : None ,
1084
+ path_ctx : None ,
1085
+ nameref,
1086
+ record_expr : None ,
1087
+ keyword : None ,
1088
+ } ;
1097
1089
1098
1090
if let Some ( record_field) = ast:: RecordExprField :: for_field_name ( & name_ref) {
1099
1091
nameref_ctx. record_expr =
@@ -1190,7 +1182,7 @@ impl<'a> CompletionContext<'a> {
1190
1182
syntax:: algo:: non_trivia_sibling ( node. into ( ) , syntax:: Direction :: Prev )
1191
1183
{
1192
1184
if let Some ( item) = ast:: Item :: cast ( n) {
1193
- match item {
1185
+ let is_inbetween = match & item {
1194
1186
ast:: Item :: Const ( it) => it. body ( ) . is_none ( ) ,
1195
1187
ast:: Item :: Enum ( it) => it. variant_list ( ) . is_none ( ) ,
1196
1188
ast:: Item :: ExternBlock ( it) => it. extern_item_list ( ) . is_none ( ) ,
@@ -1203,13 +1195,13 @@ impl<'a> CompletionContext<'a> {
1203
1195
ast:: Item :: TypeAlias ( it) => it. ty ( ) . is_none ( ) ,
1204
1196
ast:: Item :: Union ( it) => it. record_field_list ( ) . is_none ( ) ,
1205
1197
_ => false ,
1198
+ } ;
1199
+ if is_inbetween {
1200
+ return Some ( item) ;
1206
1201
}
1207
- } else {
1208
- false
1209
1202
}
1210
- } else {
1211
- false
1212
1203
}
1204
+ None
1213
1205
} ;
1214
1206
1215
1207
let kind = path. syntax ( ) . ancestors ( ) . find_map ( |it| {
@@ -1222,7 +1214,8 @@ impl<'a> CompletionContext<'a> {
1222
1214
ast:: PathExpr ( it) => {
1223
1215
if let Some ( p) = it. syntax( ) . parent( ) {
1224
1216
if ast:: ExprStmt :: can_cast( p. kind( ) ) {
1225
- if inbetween_body_and_decl_check( p) {
1217
+ if let Some ( kind) = inbetween_body_and_decl_check( p) {
1218
+ nameref_ctx. keyword = Some ( kind) ;
1226
1219
return Some ( None ) ;
1227
1220
}
1228
1221
}
@@ -1250,7 +1243,8 @@ impl<'a> CompletionContext<'a> {
1250
1243
Some ( PathKind :: Pat )
1251
1244
} ,
1252
1245
ast:: MacroCall ( it) => {
1253
- if inbetween_body_and_decl_check( it. syntax( ) . clone( ) ) {
1246
+ if let Some ( kind) = inbetween_body_and_decl_check( it. syntax( ) . clone( ) ) {
1247
+ nameref_ctx. keyword = Some ( kind) ;
1254
1248
return Some ( None ) ;
1255
1249
}
1256
1250
0 commit comments