Skip to content

Commit 6b6703e

Browse files
add subscripts and deinitializers as documentable Swift symbols
1 parent 4238f76 commit 6b6703e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Sources/SourceKitLSP/Swift/DoccDocumentation.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ fileprivate struct DocumentableSymbol {
135135
self = DocumentableSymbol(node: namedDecl, position: namedDecl.name.positionAfterSkippingLeadingTrivia)
136136
} else if let initDecl = node.as(InitializerDeclSyntax.self) {
137137
self = DocumentableSymbol(node: initDecl, position: initDecl.initKeyword.positionAfterSkippingLeadingTrivia)
138+
} else if let deinitDecl = node.as(DeinitializerDeclSyntax.self) {
139+
self = DocumentableSymbol(node: deinitDecl, position: deinitDecl.deinitKeyword.positionAfterSkippingLeadingTrivia)
138140
} else if let functionDecl = node.as(FunctionDeclSyntax.self) {
139141
self = DocumentableSymbol(node: functionDecl, position: functionDecl.name.positionAfterSkippingLeadingTrivia)
142+
} else if let subscriptDecl = node.as(SubscriptDeclSyntax.self) {
143+
self = DocumentableSymbol(node: subscriptDecl, position: subscriptDecl.positionAfterSkippingLeadingTrivia)
140144
} else if let variableDecl = node.as(VariableDeclSyntax.self) {
141145
guard let identifier = variableDecl.bindings.only?.pattern.as(IdentifierPatternSyntax.self) else {
142146
return nil

Tests/SourceKitLSPTests/DoccDocumentationTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ final class DoccDocumentationTests: XCTestCase {
116116
)
117117
}
118118

119+
func testSubscriptDeclaration() async throws {
120+
try await renderDocumentation(
121+
markedText: """
122+
/// A structure containing important information.
123+
public struct Structure {
124+
// Get the 1️⃣subscript at index
125+
subscript(in2️⃣dex: Int) -> Int {
126+
return i3️⃣ndex
127+
}
128+
}
129+
""",
130+
expectedResponses: [
131+
"1️⃣": .renderNode(kind: .symbol, path: "test/Structure/subscript(_:)"),
132+
"2️⃣": .renderNode(kind: .symbol, path: "test/Structure/subscript(_:)"),
133+
"3️⃣": .renderNode(kind: .symbol, path: "test/Structure/subscript(_:)"),
134+
]
135+
)
136+
}
137+
119138
func testClass() async throws {
120139
try await renderDocumentation(
121140
markedText: """
@@ -149,6 +168,25 @@ final class DoccDocumentationTests: XCTestCase {
149168
)
150169
}
151170

171+
func testClassDeInitializer() async throws {
172+
try await renderDocumentation(
173+
markedText: """
174+
/// A class containing important information.
175+
public class Class {
176+
/// Initi1️⃣alize the class.
177+
dein2️⃣it {
178+
// De-initi3️⃣alize stuff
179+
}
180+
}
181+
""",
182+
expectedResponses: [
183+
"1️⃣": .renderNode(kind: .symbol, path: "test/Class/deinit"),
184+
"2️⃣": .renderNode(kind: .symbol, path: "test/Class/deinit"),
185+
"3️⃣": .renderNode(kind: .symbol, path: "test/Class/deinit"),
186+
]
187+
)
188+
}
189+
152190
func testEmptyClass() async throws {
153191
try await renderDocumentation(
154192
markedText: """

0 commit comments

Comments
 (0)