Skip to content

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

Merged
merged 2 commits into from
Oct 26, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Oct 26, 2023

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

@ahoppen
Copy link
Member Author

ahoppen commented Oct 26, 2023

@swift-ci Please test

[
DocumentSymbol(
name: "varA",
detail: "Int",
detail: nil,
Copy link
Contributor

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?

Copy link
Member Author

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.

@ahoppen ahoppen force-pushed the ahoppen/document-symbols-syntax branch from 00be8ad to 973c382 Compare October 26, 2023 16:42
@ahoppen
Copy link
Member Author

ahoppen commented Oct 26, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Oct 26, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 9ebee17 into swiftlang:main Oct 26, 2023
@ahoppen ahoppen deleted the ahoppen/document-symbols-syntax branch October 26, 2023 18:59
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)")
Copy link
Contributor

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?

Copy link
Member Author

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,
Copy link
Contributor

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).

Copy link
Member Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants