Skip to content

Commit f29c97f

Browse files
committed
Update the document after cancelling the completion request to unblock sourcekitd
1 parent f7572c4 commit f29c97f

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

Tests/SourceKitLSPTests/SourceKitTests.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,15 +424,15 @@ final class SKTests: XCTestCase {
424424
"""
425425
class Foo {
426426
func slow(x: Invalid1, y: Invalid2) {
427-
x / y / x / y / x / y / x / y . 1️⃣
427+
1️⃣ x / y / x / y / x / y / x / y . 2️⃣
428428
}
429429
430430
struct Foo {
431-
let fooMember: String
431+
let 3️⃣fooMember: String
432432
}
433433
434434
func fast(a: Foo) {
435-
a.2️⃣
435+
a.4️⃣
436436
}
437437
}
438438
""",
@@ -443,7 +443,7 @@ final class SKTests: XCTestCase {
443443

444444
let requestID = RequestID.string("cancellation-test")
445445
testClient.server.handle(
446-
CompletionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"]),
446+
CompletionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["2️⃣"]),
447447
id: requestID,
448448
from: ObjectIdentifier(self)
449449
) { reply in
@@ -461,9 +461,26 @@ final class SKTests: XCTestCase {
461461

462462
let fastStartDate = Date()
463463
let fastReply = try await testClient.send(
464-
CompletionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["2️⃣"])
464+
CompletionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["4️⃣"])
465465
)
466466
XCTAssert(!fastReply.items.isEmpty)
467467
XCTAssertLessThan(Date().timeIntervalSince(fastStartDate), 2, "Fast request wasn't actually fast")
468+
469+
// Remove the slow-to-typecheck line. This causes the implicit diagnostics request for the push diagnostics
470+
// notification to get cancelled, which unblocks sourcekitd for later tests.
471+
testClient.send(
472+
DidChangeTextDocumentNotification(
473+
textDocument: VersionedTextDocumentIdentifier(uri, version: 2),
474+
contentChanges: [
475+
TextDocumentContentChangeEvent(range: positions["1️⃣"]..<positions["2️⃣"], text: "")
476+
]
477+
)
478+
)
479+
480+
// Check that semantic functionality based on the AST is working again.
481+
let symbolInfo = try await testClient.send(
482+
SymbolInfoRequest(textDocument: TextDocumentIdentifier(uri), position: positions["3️⃣"])
483+
)
484+
XCTAssertGreaterThan(symbolInfo.count, 0)
468485
}
469486
}

0 commit comments

Comments
 (0)