-
Notifications
You must be signed in to change notification settings - Fork 314
Implement DocumentSymbolsRequest using SwiftSyntax #926
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
Implement DocumentSymbolsRequest using SwiftSyntax #926
Conversation
@swift-ci Please test |
[ | ||
DocumentSymbol( | ||
name: "varA", | ||
detail: "Int", | ||
detail: 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.
Is detail
always nil
now?
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.
Yes. We could try to get the type from a variable declaration if it is explicitly specified but I think it’s more confusing if you have it for let x: Int = 1
but not for let x = 1
, so I chose to just always set it to nil
.
00be8ad
to
973c382
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
extension SwiftLanguageServer { | ||
public func documentSymbol(_ req: DocumentSymbolRequest) async throws -> DocumentSymbolResponse? { | ||
guard let snapshot = self.documentManager.latestSnapshot(req.textDocument.uri) else { | ||
logger.error("failed to find snapshot for url \(req.textDocument.uri.forLogging)") |
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 have this in so many places. Is requesting a snapshot and not finding it ever not an error? ie. should we just always log?
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 idea. Here we go: #943
|
||
return record( | ||
node: node, | ||
name: node.qualifiedDeclName, |
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.
qualified
to me suggests eg. Type.member
rather than just the full name (including parentheses).
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.
Ah, yeah, qualified really isn’t the term here. Renaming to declName
in #944
symbols, | ||
.documentSymbols([ | ||
func testUnicode1() async throws { | ||
try await assertDocumentSymbols("1️⃣struct 2️⃣Żółć3️⃣ { }4️⃣") { positions in |
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.
Nice 👍
Before doing that, I refactored the document symbol tests to be more modular so that if one fails, you can actually tell what the failure is. It’s worth noting the slight differences in results introduced by the second commit that starts using swift-syntax. IMO all changes are improvements