From 6ad35c43d10f23480706da47fe00eac98559210c Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Thu, 3 Aug 2023 19:23:04 -0700 Subject: [PATCH] Fix a non-deterministic test failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We weren’t handling the notifications sent from the `DidOpenTextDocumentNotification`, which could cause test failures based on the notification timings relative to the notifications from the `DidChangeTextDocumentNotification`. --- Tests/SourceKitLSPTests/LocalSwiftTests.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/SourceKitLSPTests/LocalSwiftTests.swift b/Tests/SourceKitLSPTests/LocalSwiftTests.swift index ca3ffd3d8..b368a7e43 100644 --- a/Tests/SourceKitLSPTests/LocalSwiftTests.swift +++ b/Tests/SourceKitLSPTests/LocalSwiftTests.swift @@ -1487,7 +1487,7 @@ final class LocalSwiftTests: XCTestCase { swiftLanguageServer.reusedNodeCallback = { reusedNodes.append($0) } sk.allowUnexpectedNotification = false - sk.send(DidOpenTextDocumentNotification(textDocument: TextDocumentItem( + sk.sendNoteSync(DidOpenTextDocumentNotification(textDocument: TextDocumentItem( uri: uri, language: .swift, version: 0, @@ -1497,20 +1497,20 @@ final class LocalSwiftTests: XCTestCase { class bar { } """ - ))) - - let didChangeTextDocumentExpectation = self.expectation(description: "didChangeTextDocument") + )), { (note: LanguageServerProtocol.Notification) -> Void in + log("Received diagnostics for open - syntactic") + }, { (note: LanguageServerProtocol.Notification) -> Void in + log("Received diagnostics for open - semantic") + }) + sk.sendNoteSync(DidChangeTextDocumentNotification(textDocument: .init(uri, version: 1), contentChanges: [ .init(range: Range(Position(line: 2, utf16index: 7)), text: "a"), ]), { (note: LanguageServerProtocol.Notification) -> Void in log("Received diagnostics for text edit - syntactic") - didChangeTextDocumentExpectation.fulfill() }, { (note: LanguageServerProtocol.Notification) -> Void in log("Received diagnostics for text edit - semantic") }) - self.wait(for: [didChangeTextDocumentExpectation], timeout: defaultTimeout) - XCTAssertEqual(reusedNodes.count, 1) let firstNode = try XCTUnwrap(reusedNodes.first)