Skip to content

Commit 70298ef

Browse files
committed
[CodeCompletion] Ignore parsed completion decls in the first pass
If a code completion happens inside an attribute (or in the decl), we should not insert parsed decls to the AST in the first pass. rdar://problem/65898101
1 parent 4b6641f commit 70298ef

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,7 +3754,8 @@ Parser::parseDecl(ParseDeclOptions Flags,
37543754
StaticSpelling, tryLoc, HasLetOrVarKeyword);
37553755
StaticLoc = SourceLoc(); // we handled static if present.
37563756
MayNeedOverrideCompletion = true;
3757-
if (DeclResult.hasCodeCompletion() && isCodeCompletionFirstPass())
3757+
if ((AttrStatus.hasCodeCompletion() || DeclResult.hasCodeCompletion())
3758+
&& isCodeCompletionFirstPass())
37583759
return;
37593760
std::for_each(Entries.begin(), Entries.end(), Handler);
37603761
if (auto *D = DeclResult.getPtrOrNull())
@@ -3801,7 +3802,8 @@ Parser::parseDecl(ParseDeclOptions Flags,
38013802
llvm::SmallVector<Decl *, 4> Entries;
38023803
DeclParsingContext.setCreateSyntax(SyntaxKind::EnumCaseDecl);
38033804
DeclResult = parseDeclEnumCase(Flags, Attributes, Entries);
3804-
if (DeclResult.hasCodeCompletion() && isCodeCompletionFirstPass())
3805+
if ((AttrStatus.hasCodeCompletion() || DeclResult.hasCodeCompletion()) &&
3806+
isCodeCompletionFirstPass())
38053807
break;
38063808
std::for_each(Entries.begin(), Entries.end(), Handler);
38073809
if (auto *D = DeclResult.getPtrOrNull())
@@ -3845,7 +3847,8 @@ Parser::parseDecl(ParseDeclOptions Flags,
38453847
DeclResult = parseDeclSubscript(StaticLoc, StaticSpelling, Flags,
38463848
Attributes, Entries);
38473849
StaticLoc = SourceLoc(); // we handled static if present.
3848-
if (DeclResult.hasCodeCompletion() && isCodeCompletionFirstPass())
3850+
if ((AttrStatus.hasCodeCompletion() || DeclResult.hasCodeCompletion()) &&
3851+
isCodeCompletionFirstPass())
38493852
break;
38503853
std::for_each(Entries.begin(), Entries.end(), Handler);
38513854
MayNeedOverrideCompletion = true;
@@ -4024,6 +4027,8 @@ Parser::parseDecl(ParseDeclOptions Flags,
40244027
CodeCompletion->setAttrTargetDeclKind(DK);
40254028
}
40264029
DeclResult.setHasCodeCompletion();
4030+
if (isCodeCompletionFirstPass())
4031+
return DeclResult;
40274032
}
40284033

40294034
if (DeclResult.isNonNull()) {

0 commit comments

Comments
 (0)