Skip to content

Show deinit in document symbols #1397

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 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Sources/SourceKitLSP/Swift/DocumentSymbols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ fileprivate final class DocumentSymbolsFinder: SyntaxAnyVisitor {
return .skipChildren
}

override func visit(_ node: DeinitializerDeclSyntax) -> SyntaxVisitorContinueKind {
return record(
node: node,
name: node.deinitKeyword.text,
symbolKind: .null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of weird, but could make constructor?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about it as well but then felt that constructor is weird because it’s not a constructor… But I don’t have strong opinions here.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it would be more like a function (assuming that doesn't break any invariants), but also don't feel strongly 🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

I just checked and VS Code at least uses the same icon for constructor and function, so it’s odd if deinit uses a different icon. clangd uses constructor, so let’s just do that as well.

Screenshot 2024-06-03 at 09 07 41

range: node.rangeWithoutTrivia,
selection: node.deinitKeyword.rangeWithoutTrivia
)
}

override func visit(_ node: EnumCaseElementSyntax) -> SyntaxVisitorContinueKind {
let rangeEnd =
if let parameterClause = node.parameterClause {
Expand Down
29 changes: 29 additions & 0 deletions Tests/SourceKitLSPTests/DocumentSymbolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,35 @@ final class DocumentSymbolTests: XCTestCase {
]
}
}

func testShowDeinit() async throws {
try await assertDocumentSymbols(
"""
1️⃣class 2️⃣Foo3️⃣ {
4️⃣deinit5️⃣ {
}6️⃣
}7️⃣
"""
) { positions in
[
DocumentSymbol(
name: "Foo",
kind: .class,
range: positions["1️⃣"]..<positions["7️⃣"],
selectionRange: positions["2️⃣"]..<positions["3️⃣"],
children: [
DocumentSymbol(
name: "deinit",
kind: .null,
range: positions["4️⃣"]..<positions["6️⃣"],
selectionRange: positions["4️⃣"]..<positions["5️⃣"],
children: []
)
]
)
]
}
}
}

fileprivate func assertDocumentSymbols(
Expand Down