@@ -1263,6 +1263,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
1263
1263
bool HasSpace = false ;
1264
1264
bool ShouldCompleteCallPatternAfterParen = true ;
1265
1265
bool PreferFunctionReferencesToCalls = false ;
1266
+ bool AttTargetIsIndependent = false ;
1266
1267
Optional<DeclKind> AttTargetDK;
1267
1268
Optional<StmtKind> ParentStmtKind;
1268
1269
@@ -1351,13 +1352,6 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
1351
1352
void setAttrTargetDeclKind (Optional<DeclKind> DK) override {
1352
1353
if (DK == DeclKind::PatternBinding)
1353
1354
DK = DeclKind::Var;
1354
-
1355
- // If the target is already set to 'Module', that means the completion
1356
- // should be performed as if it's not tied to any specific decl.
1357
- // see 'completeDeclAttrBeginning()'
1358
- if (AttTargetDK == DeclKind::Module)
1359
- DK = None;
1360
-
1361
1355
AttTargetDK = DK;
1362
1356
}
1363
1357
@@ -4618,10 +4612,7 @@ void CodeCompletionCallbacksImpl::completeDeclAttrBeginning(
4618
4612
Kind = CompletionKind::AttributeBegin;
4619
4613
IsInSil = Sil;
4620
4614
CurDeclContext = P.CurDeclContext ;
4621
-
4622
- // Use 'DeclKind::Module' as the indicator of "This is independent attribute".
4623
- if (isIndependent)
4624
- AttTargetDK = DeclKind::Module;
4615
+ AttTargetIsIndependent = isIndependent;
4625
4616
}
4626
4617
4627
4618
void CodeCompletionCallbacksImpl::completeInPrecedenceGroup (SyntaxKind SK) {
@@ -5385,15 +5376,16 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5385
5376
}
5386
5377
5387
5378
case CompletionKind::AttributeBegin: {
5388
- assert (AttTargetDK != DeclKind::Module &&
5389
- " 'setAttrTargetDeclKind()' hasn't been called" );
5390
- Lookup.getAttributeDeclCompletions (IsInSil, AttTargetDK);
5379
+ auto DK = AttTargetDK;
5380
+ if (AttTargetIsIndependent)
5381
+ DK = None;
5382
+ Lookup.getAttributeDeclCompletions (IsInSil, DK);
5391
5383
5392
5384
// TypeName at attribute position after '@'.
5393
5385
// - VarDecl: Property Wrappers.
5394
5386
// - ParamDecl/VarDecl/FuncDecl: Function Buildres.
5395
- if (!AttTargetDK || *AttTargetDK == DeclKind::Var ||
5396
- *AttTargetDK == DeclKind::Param || *AttTargetDK == DeclKind::Func)
5387
+ if (!DK. hasValue () || *DK == DeclKind::Var || *DK == DeclKind::Param ||
5388
+ *DK == DeclKind::Func)
5397
5389
Lookup.getTypeCompletionsInDeclContext (
5398
5390
P.Context .SourceMgr .getCodeCompletionLoc ());
5399
5391
break ;
0 commit comments