-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SourceKit] Add a request to get the semantic tokens of a file #69294
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
@swift-ci Please smoke test |
@swift-ci Please build toolchain macOS |
ff55f00
to
8441396
Compare
@swift-ci Please smoke test |
8441396
to
e543961
Compare
We need this request for semantic highlighting in LSP. Previously, we were getting the semantic tokens using a 0,0 edit after a document update notification but that will no longer be possible if we open the documents in syntactic only mode.
e543961
to
4bc03f8
Compare
@swift-ci Please smoke test |
@@ -0,0 +1,17 @@ | |||
// RUN: %sourcekitd-test -req=semantic-tokens %s -- %s | %FileCheck %s | |||
|
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.
Do we get semantic tokens of buffers within a primary file?
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.
We do now. Added 1776e37
@swift-ci Please smoke test |
// IN_BUFFER: source.lang.swift.ref.struct | ||
// IN_BUFFER: key.kind: source.lang.swift.ref.class | ||
|
||
// Check that we don't get semantic tokens inside the buffer when requesting semantic tokens for the outer type |
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.
// Check that we don't get semantic tokens inside the buffer when requesting semantic tokens for the outer type | |
// Check that we don't get semantic tokens inside the buffer when requesting semantic tokens for the outer file |
if (!InvocationError.empty()) { | ||
LOG_WARN_FUNC("error creating ASTInvocation: " << InvocationError); | ||
} |
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.
Where does this actually show up? Is it ever more obvious than just the actual error response?
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.
This is copied from
and
Not sure if it’s more obvious but it’s also not less obvious so 🤷🏽
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.
LGTM modulo the below comment
lib/IDE/SourceEntityWalker.cpp
Outdated
} else if (auto ME = dyn_cast<MacroExpansionExpr>(E)) { | ||
// Add a reference to the macro | ||
auto macroRef = ME->getMacroRef(); | ||
if (auto *macroDecl = dyn_cast_or_null<MacroDecl>(macroRef.getDecl())) { | ||
auto macroRefType = macroDecl->getDeclaredInterfaceType(); | ||
if (!passReference( | ||
macroDecl, macroRefType, ME->getMacroNameLoc(), | ||
ReferenceMetaData(SemaReferenceKind::DeclRef, llvm::None))) | ||
return Action::Stop(); | ||
} |
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.
Out of curiosity, why remove this? Wouldn't this impact things like cursor info?
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.
My assumption was that we end up passing the reference through some other means. But based on the failing test, seems like that isn't the case.
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.
We were passing a reference twice and I thought removing this fixed it. But looks like I didn’t rebuild before running tests or something along those lines. I need to look into it again.
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.
OK, we needed to check that the MacroExpansionExpr
didn’t have a SubstituteDecl
. Could you double-check that the comment I wrote in my new version of this PR makes sense?
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.
Looks good to me!
1776e37
to
2507e0e
Compare
@swift-ci Please smoke test |
We need this request for semantic highlighting in LSP. Previously, we were getting the semantic tokens using a 0,0 edit after a document update notification but that will no longer be possible if we open the documents in syntactic only mode.