-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SourceKit] Don’t provide incorrect semantic highlighting of nil
in case statements as enum decl element
#60328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2b75a15
to
51bb420
Compare
if (D == D->getASTContext().getOptionalNoneDecl() && Length == 3) { | ||
// 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. | ||
// Detect this case if 'none' was spelled with 3 characters, which | ||
// indicates that it was rewritten from 'nil'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Length == 3
might be enough in real world, but SM.extractText(Range, BufferID) == "nil"
is more explicit, safe, and not so heavy. If we don't have strong reason not to, could you check the actual spelling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, other "deciding annotate or not" checks are in visitDeclReference()
instead of annotate()
. Could you move this logic to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestions, thanks. I though I would have needed to go to the lexer to get the original source text but of course I don’t.
51bb420
to
872f01d
Compare
@swift-ci Please smoke test |
// Detect this case if 'none' was spelled with 3 characters, which | ||
// indicates that it was rewritten from 'nil'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last sentence is not correct anymore :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching it. I removed the last sentence.
@@ -963,6 +963,17 @@ class SemanticAnnotator : public SourceEntityWalker { | |||
if (AvailableAttr::isUnavailable(D)) | |||
return true; | |||
|
|||
auto &SM = D->getASTContext().SourceMgr; | |||
if (D == D->getASTContext().getOptionalNoneDecl() && | |||
SM.extractText(Range) == "nil") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SM.extractText(Range) == "nil") { | |
SM.extractText(Range, BufferID) == "nil") { |
So it skips findBufferContainingLoc()
operation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thanks 👍
… 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 swiftlang/sourcekit-lsp#599 rdar://97961865
872f01d
to
1e9eac6
Compare
@swift-ci Please smoke test |
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. Detect this case if 'none' was spelled with 3 characters, which indicates that it was rewritten from 'nil'.
Resolves swiftlang/sourcekit-lsp#599
rdar://97961865