-
Notifications
You must be signed in to change notification settings - Fork 314
Implement semantic highlighting for Swift #414
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
3740394
to
4bddd07
Compare
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, I’ve left a few™ comments inline. Don’t be afraid by the amount. Overall, I think the PR is really good and I don’t think it’s anything too major.
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.
I’ve added some more comments inline.
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 a lot for continuing to push this through. 😍
I’ve got a few more comments inline, but I think we’re nearly there.
I have removed the syntactic tokens for now, which should resolve the performance issues in large files. Also the language server now parses lexical |
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.
I was trying this out in vscode, and had a couple of questions:
- Is
defaultLibrary
not working, or is vscode just not using that from its builtin themes? I don't see any differentiation. - It seems like in "public func" the theme wants to emphasize the "public" (modifier) instead of the "func" (keyword). I would have expected the opposite, or that they would look the same. Do you know what other language servers are doing here?
This doesn't need to block the PR though.
Other than my comment about the timeout, I think this is probably ready to go, although @ahoppen should probably sign off on it as well. Thanks for your hard work @fwcd !
@swift-ci please test |
The default theme doesn't use it, but you can confirm it's there by using the |
I've bisected the PR and found that 4bbff3d broke (at least) the document symbol test, since it changes the semantics of the |
@swift-ci please test |
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.
I just went through this again and have a couple more inline comments. Once they’re taken care of, I’m go for merge 🚀.
I also filed SR-15058 with some areas for improvement that are out of scope for this PR, to make sure we don’t loose track of them. |
- Make makeToken a fileprivate initializer instead - Fix doc comments on withMutableTokensOfEachKind - Rename `previousLineCount` to `replacedLineCount` - Fix token shifting logic - Add another test case for inserting tokens - Return empty document tokens if we don't get an edit response - Update DocumentSymbol.children to be non-optional - Rename DocumentSymbolTest to DocumentSymbolTests ...to be consistent with the file name and the other test modules. - Fix indentation in DocumentSymbolTests - Fix doc comment on Modifier.lspName - Remove no-longer-needed useName from token parser These were only needed for syntactic tokens, which we decided not to include in swiftlang#414 for now. - Add test case for identifiers only backticked on one side - Parse tokens into inout array
@swift-ci please etst |
@swift-ci please test |
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.
I’ve got two minor follow-up comments to my last review.
Could you also squash your commits?
Sure, should I squash the entire PR into a single commit or do you think that a more granular splitting would be better, given that the PR has become pretty large already? |
I can’t really think of any way the changes can be split up into commits that are at least somewhat independent, so I think one big commit is fine. |
Okay, I'd vote to keep 4bbff3d separate though, since it is a (slight) change to the accessors' semantics that isn't directly related to semantic highlighting per se. |
Sounds good. 👍 If you have more of these commits, I think keeping them separate would be good. All I tried to say is that I don’t think it’s worth the effort to artificially split up the PR into smaller commits. |
This is an implementation of LSP's semantic tokens for Swift. Both lexical and semantic tokens are provided by using the syntaxmap and the semantic annotations provided as part of SourceKit's open responses and document update notifications. While lexical tokens are parsed and stored in the DocumentManager synchronously, semantic tokens are provided asynchronously. If an edit occurs, tokens are automatically shifted by the DocumentManager. This is especially relevant for lexical tokens, which are updated in deltas. In addition, unit tests are added that assert that both lexical and semantic tokens are provided and shifted correctly upon edits.
@swift-ci Please test |
|
The coding of document symbols now correctly expects an empty children array.
Good catch, should be fixed now. |
@swift-ci Please test |
This is a reboot of @prostakm's implementation of semantic highlighting in #279, using the LSP structures from #388 and the suggestions from #279 (comment).
Both lexical and semantic tokens are now stored in
Document
s and updated whenever a document is updated or changed. Lexical tokens are updated incrementally inopenDocument
andchangeDocument
and semantic tokens are updated all at once inhandleDocumentUpdate
.Implementation Progress
DocumentManager
let document = ...
thedo
stays highlighted as a keyword and isn't removed, since the edit range never overlaps with it (this is solved by checking whether an edit that is directly adjacent to a token uses a whitespace character at the adjacent position)Future Work
keys.substructure
(i.e. revert 1e65730) and address the performance issues in big files (see this thread)