[SourceKit] Don’t provide incorrect semantic highlighting of nil in case statements as enum decl element

If a 'nil' literal occurs in a swift-case statment, it gets replaced by a reference to 'Optional.none' in the AST. We want to continue highlighting 'nil' as a keyword and not as an enum element.

Resolves apple/sourcekit-lsp#599
rdar://97961865
This commit is contained in:
Alex Hoppen
2022-08-01 09:34:36 +02:00
parent db7d1e7517
commit 1e9eac6c64
2 changed files with 40 additions and 0 deletions

View File

@@ -963,6 +963,15 @@ public:
if (AvailableAttr::isUnavailable(D))
return true;
auto &SM = D->getASTContext().SourceMgr;
if (D == D->getASTContext().getOptionalNoneDecl() &&
SM.extractText(Range, BufferID) == "nil") {
// If a 'nil' literal occurs in a swift-case statement, it gets replaced
// by a reference to 'Optional.none' in the AST. We want to continue
// highlighting 'nil' as a keyword and not as an enum element.
return true;
}
if (CtorTyRef)
D = CtorTyRef;
annotate(D, /*IsRef=*/true, Range);