Skip to content

Commit bd55793

Browse files
authored
Merge pull request #1964 from ahoppen/refactor-mulit-edit-test
Refactor `testMultiEditFixitCodeActionPrimary` to not rely on availability diagnostics
2 parents 254ebaa + 6c4c45f commit bd55793

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

Tests/SourceKitLSPTests/LocalSwiftTests.swift

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -646,51 +646,45 @@ final class LocalSwiftTests: XCTestCase {
646646
}
647647

648648
func testMultiEditFixitCodeActionPrimary() async throws {
649-
// FIXME: Update this test to use different syntax to test multi-fixit diagnostics
650-
try XCTSkipIf(true, "https://github.com/swiftlang/sourcekit-lsp/issues/1961")
651-
652-
let testClient = try await TestSourceKitLSPClient(capabilities: quickFixCapabilities, usePullDiagnostics: false)
653-
let url = URL(fileURLWithPath: "/\(UUID())/a.swift")
654-
let uri = DocumentURI(url)
655-
656-
testClient.openDocument(
649+
let project = try await IndexedSingleSwiftFileTestProject(
657650
"""
658-
@available(*, introduced: 10, deprecated: 11)
659-
func foo() {}
651+
func foo(a: Int, b: Int) {}
652+
func test() {
653+
foo(1️⃣1, 2️⃣2)
654+
}
660655
""",
661-
uri: uri
656+
capabilities: quickFixCapabilities,
657+
allowBuildFailure: true
662658
)
663-
664-
let diags = try await testClient.nextDiagnosticsNotification()
665-
XCTAssertEqual(diags.diagnostics.count, 1)
666-
let diagnostic = diags.diagnostics.first
659+
let diags = try await project.testClient.send(
660+
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(project.fileURI))
661+
)
662+
let diagnostic = try XCTUnwrap(diags.fullReport?.items.only)
667663

668664
let request = CodeActionRequest(
669-
range: Position(line: 0, utf16index: 1)..<Position(line: 0, utf16index: 10),
665+
range: diagnostic.range,
670666
context: CodeActionContext(
671667
diagnostics: [try XCTUnwrap(diagnostic, "expected diagnostic to be available")],
672668
only: nil
673669
),
674-
textDocument: TextDocumentIdentifier(uri)
670+
textDocument: TextDocumentIdentifier(project.fileURI)
675671
)
676-
let response = try await testClient.send(request)
672+
let response = try await project.testClient.send(request)
677673

678-
XCTAssertNotNil(response)
679674
guard case .codeActions(let codeActions) = response else {
680675
XCTFail("Expected code actions as response")
681676
return
682677
}
683678
let quickFixes = codeActions.filter { $0.kind == .quickFix }
684-
XCTAssertEqual(quickFixes.count, 1)
685-
guard let fixit = quickFixes.first else { return }
679+
let fixit = try XCTUnwrap(quickFixes.only)
686680

687-
XCTAssertEqual(fixit.title, "Remove ': 10'...")
681+
XCTAssertEqual(fixit.title, "Insert 'a: '...")
688682
XCTAssertEqual(fixit.diagnostics?.count, 1)
689683
XCTAssertEqual(
690-
fixit.edit?.changes?[uri],
684+
fixit.edit?.changes?[project.fileURI],
691685
[
692-
TextEdit(range: Position(line: 0, utf16index: 24)..<Position(line: 0, utf16index: 28), newText: ""),
693-
TextEdit(range: Position(line: 0, utf16index: 40)..<Position(line: 0, utf16index: 44), newText: ""),
686+
TextEdit(range: Range(project.positions["1️⃣"]), newText: "a: "),
687+
TextEdit(range: Range(project.positions["2️⃣"]), newText: "b: "),
694688
]
695689
)
696690
}

0 commit comments

Comments
 (0)