Skip to content

Commit 9988930

Browse files
authored
Merge pull request #959 from ahoppen/ahoppen/built-in-diags-test-case
Add a test case for diagnostics produced by the built-in swift-syntax
2 parents e0173c8 + 13d9eda commit 9988930

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Tests/SourceKitLSPTests/PullDiagnosticsTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,30 @@ final class PullDiagnosticsTests: XCTestCase {
106106
].contains(action.title)
107107
)
108108
}
109+
110+
func testNotesFromIntegratedSwiftSyntaxDiagnostics() async throws {
111+
// Create a workspace that has compile_commands.json so that it has a build system but no compiler arguments
112+
// for test.swift so that we fall back to producing diagnostics from the built-in swift-syntax.
113+
let ws = try await MultiFileTestWorkspace(files: [
114+
"test.swift": "func foo() 1️⃣{2️⃣",
115+
"compile_commands.json": "[]"
116+
])
117+
118+
let (uri, positions) = try ws.openDocument("test.swift")
119+
120+
let report = try await ws.testClient.send(DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri)))
121+
guard case .full(let fullReport) = report else {
122+
XCTFail("Expected full diagnostics report")
123+
return
124+
}
125+
XCTAssertEqual(fullReport.items.count, 1)
126+
let diagnostic = try XCTUnwrap(fullReport.items.first)
127+
XCTAssertEqual(diagnostic.message, "expected '}' to end function")
128+
XCTAssertEqual(diagnostic.range, Range(positions["2️⃣"]))
129+
130+
XCTAssertEqual(diagnostic.relatedInformation?.count, 1)
131+
let note = try XCTUnwrap(diagnostic.relatedInformation?.first)
132+
XCTAssertEqual(note.message, "to match this opening '{'")
133+
XCTAssertEqual(note.location.range, positions["1️⃣"]..<positions["2️⃣"])
134+
}
109135
}

0 commit comments

Comments
 (0)