-
Notifications
You must be signed in to change notification settings - Fork 327
🚥 Implement Document Highlight for all return / throws (function/closure/accessor/init/deinit) and break / continue (for/while/repeat...while) #2403
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
base: main
Are you sure you want to change the base?
Conversation
…e/accessor/init/deinit) and break / continue (for/while/repeat...while)
ahoppen
left a comment
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.
Very nice and excited for this. 😍
A preliminary review, as you already noted in the PR description, a few tests would be good 😉
| if node.lookupControlStructure() == targetStructure { | ||
| highlights.append( | ||
| DocumentHighlight( | ||
| range: snapshot.absolutePositionRange(of: node.positionAfterSkippingLeadingTrivia..<node.endPosition), |
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.
Should we just highlight the control flow keyword (eg. return). I think that might look nicer, especially if the returned expression spans multiple lines.
| return nil | ||
| } | ||
|
|
||
| guard let targetStructure = Syntax(tokenSyntax).parent!.lookupControlStructure() else { |
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 shouldn’t force unwrap the parent here.
| } | ||
| } | ||
|
|
||
| private func documentSymbolHighlightHelper( |
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 would give this a more descriptive name which highlights that this is about control flow keyword highlighting.
| } | ||
| } | ||
|
|
||
| override func visit(_ node: BreakStmtSyntax) -> SyntaxVisitorContinueKind { |
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.
You shouldn’t need to repeat the list of control flow nodes if this is a SyntaxAnyVisitor and you add a visitAny override.


Upgrades
textDocument/documentHighlightto highlight various return / throw statements corresponding to a function / closure / accessor / init / deinit, and break / continue statements corresponding to a loop, thereby allowing us to not wonder about which statements could cause an exit from a function or loop.This also makes use of a new API introduced in SwiftLexicalLookup Library in Swift Syntax.
This doesn't break existing code. This is Additive.
Fixes: Highlight related identifiers for control flow keywords #2400
This is the original PR. New API for Swift Syntax introduced in 🚥 Introduce a new Lexical query
lookupControlStructureto theSwiftLexicalLookupLibrary swift-syntax#3216I don't think there's any risk associated with this new feature.
Tests and Docs are yet to be written. The code & This PR description will also be polished.
Suggested by @ahoppen and Open to be reviewed by anyone. Note: At the current state, the code is messy since I was focused on getting it to work, will polish it.