Skip to content

Commit bc03796

Browse files
committed
[CodeCompletion] Stop using DeclKind::Module as a isIndependent indicator
1 parent 09ca68e commit bc03796

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
12631263
bool HasSpace = false;
12641264
bool ShouldCompleteCallPatternAfterParen = true;
12651265
bool PreferFunctionReferencesToCalls = false;
1266+
bool AttTargetIsIndependent = false;
12661267
Optional<DeclKind> AttTargetDK;
12671268
Optional<StmtKind> ParentStmtKind;
12681269

@@ -1351,13 +1352,6 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13511352
void setAttrTargetDeclKind(Optional<DeclKind> DK) override {
13521353
if (DK == DeclKind::PatternBinding)
13531354
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-
13611355
AttTargetDK = DK;
13621356
}
13631357

@@ -4618,10 +4612,7 @@ void CodeCompletionCallbacksImpl::completeDeclAttrBeginning(
46184612
Kind = CompletionKind::AttributeBegin;
46194613
IsInSil = Sil;
46204614
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;
46254616
}
46264617

46274618
void CodeCompletionCallbacksImpl::completeInPrecedenceGroup(SyntaxKind SK) {
@@ -5385,15 +5376,16 @@ void CodeCompletionCallbacksImpl::doneParsing() {
53855376
}
53865377

53875378
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);
53915383

53925384
// TypeName at attribute position after '@'.
53935385
// - VarDecl: Property Wrappers.
53945386
// - 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)
53975389
Lookup.getTypeCompletionsInDeclContext(
53985390
P.Context.SourceMgr.getCodeCompletionLoc());
53995391
break;

0 commit comments

Comments
 (0)