Skip to content

Commit 2ba6fa0

Browse files
fix documentation comments for enum case statements
1 parent af02df9 commit 2ba6fa0

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

Sources/SourceKitLSP/Documentation/DocumentationManager.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,12 @@ fileprivate final class DocumentableSymbolFinder: SyntaxAnyVisitor {
247247
return .skipChildren
248248
}
249249

250-
override func visit(_ node: EnumCaseElementSyntax) -> SyntaxVisitorContinueKind {
251-
let symbolPosition = node.name.positionAfterSkippingLeadingTrivia
252-
if node.range.contains(cursorPosition) || cursorPosition < symbolPosition {
253-
setResult(node: node, position: symbolPosition)
250+
override func visit(_ node: EnumCaseDeclSyntax) -> SyntaxVisitorContinueKind {
251+
for element in node.elements {
252+
let symbolPosition = element.name.positionAfterSkippingLeadingTrivia
253+
if element.range.contains(cursorPosition) || cursorPosition < symbolPosition {
254+
setResult(node: node, position: symbolPosition)
255+
}
254256
}
255257
return .skipChildren
256258
}

Tests/SourceKitLSPTests/ConvertDocumentationTests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#if canImport(SwiftDocC)
14+
import Foundation
1415
import LanguageServerProtocol
1516
import SKLogging
1617
import SKTestSupport
@@ -219,6 +220,53 @@ final class ConvertDocumentationTests: XCTestCase {
219220
)
220221
}
221222

223+
func testEditDocLineCommentAboveEnumCaseElement() async throws {
224+
let testClient = try await TestSourceKitLSPClient()
225+
let uri = DocumentURI(for: .swift)
226+
let positions = testClient.openDocument(
227+
"""
228+
/// An enumeration containing important information.
229+
public enum Enum {
230+
/// The first case.
231+
case first
232+
233+
/// The 0️⃣second case.
234+
case second
235+
236+
// The third case.
237+
case third(Int)
238+
}
239+
""",
240+
uri: uri
241+
)
242+
243+
// Make sure that the initial documentation comment is present in the response
244+
await convertDocumentation(
245+
testClient: testClient,
246+
uri: uri,
247+
positions: positions,
248+
expectedResponses: [.renderNode(kind: .symbol, containing: "The second case")]
249+
)
250+
251+
// Change the content of the documentation comment
252+
testClient.send(
253+
DidChangeTextDocumentNotification(
254+
textDocument: VersionedTextDocumentIdentifier(uri, version: 2),
255+
contentChanges: [
256+
TextDocumentContentChangeEvent(range: positions["0️⃣"]..<positions["0️⃣"], text: "very ")
257+
]
258+
)
259+
)
260+
261+
// Make sure that the new documentation comment is present in the response
262+
await convertDocumentation(
263+
testClient: testClient,
264+
uri: uri,
265+
positions: positions,
266+
expectedResponses: [.renderNode(kind: .symbol, containing: "The very second case")]
267+
)
268+
}
269+
222270
func testProtocol() async throws {
223271
try await convertDocumentation(
224272
swiftFile: """

0 commit comments

Comments
 (0)