Skip to content
Open
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
6 changes: 4 additions & 2 deletions Sources/SwiftLanguageService/SymbolGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ private struct DocumentableSymbol {
self.documentationComments = node.leadingTrivia.flatMap { trivia -> [String] in
switch trivia {
case .docLineComment(let comment):
return [String(comment.dropFirst(3).trimmingCharacters(in: .whitespaces))]
// Preserve leading whitespace for DocC indentation parsing (issue #2119)
return [String(comment.dropFirst(3))]
case .docBlockComment(let comment):
return comment.dropFirst(3)
.dropLast(2)
.split(whereSeparator: \.isNewline)
.map { String($0).trimmingCharacters(in: .whitespaces) }
// Preserve leading whitespace for DocC indentation parsing (issue #2119)
.map(String.init)
default:
return []
}
Expand Down
67 changes: 67 additions & 0 deletions Tests/SourceKitLSPTests/DoccDocumentationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,72 @@ final class DoccDocumentationTests: SourceKitLSPTestCase {
)
}

func testMultilineReturnsInDocLineComment() async throws {
// Regression test for https://github.com/swiftlang/vscode-swift/issues/2119
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(
"""
/// Checks whether a field exists.
///
/// - Returns: One of the following
/// * 1️⃣0: field does not exist
/// * 1: field exists
public func hexists() -> Int { return 1 }
""",
uri: uri
)
let response = try await testClient.send(
DoccDocumentationRequest(
textDocument: TextDocumentIdentifier(uri),
position: positions["1️⃣"]
)
)
let renderNodeString = response.renderNode
XCTAssertTrue(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use renderDocumentation() like the other tests in this suite. It has an expectation called contains that does exactly this.

renderNodeString.contains("0: field does not exist"),
"Expected continuation text in render node"
)
XCTAssertFalse(
renderNodeString.contains("\"kind\" : \"content\""),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see how this tests whether or not a discussion section exists in the output. Also, looking for the absence of a very specific string in serialized JSON output is very brittle.

"Continuation lines should not create a separate Discussion section"
)
}

func testMultilineReturnsInDocBlockComment() async throws {
// Regression test for https://github.com/swiftlang/vscode-swift/issues/2119
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI(for: .swift)
let positions = testClient.openDocument(
"""
/**
Checks whether a field exists.

- Returns: One of the following
* 1️⃣0: field does not exist
* 1: field exists
*/
public func hexists() -> Int { return 1 }
""",
uri: uri
)
let response = try await testClient.send(
DoccDocumentationRequest(
textDocument: TextDocumentIdentifier(uri),
position: positions["1️⃣"]
)
)
let renderNodeString = response.renderNode
XCTAssertTrue(
renderNodeString.contains("0: field does not exist"),
"Expected continuation text in render node"
)
XCTAssertFalse(
renderNodeString.contains("\"kind\" : \"content\""),
"Continuation lines should not create a separate Discussion section"
)
}

func testStructure() async throws {
try await renderDocumentation(
markedText: """
Expand Down Expand Up @@ -551,6 +617,7 @@ final class DoccDocumentationTests: SourceKitLSPTestCase {
)
}


// MARK: Markdown Articles and Extensions

func testMarkdownArticle() async throws {
Expand Down