@@ -913,6 +913,55 @@ final class SemanticTokensTests: XCTestCase {
913
913
)
914
914
}
915
915
916
+ func testCloseAndReopenDocumentWithSameDocumentVersion( ) async throws {
917
+ // When neovim detects a change of the document on-disk (eg. caused by git operations). It closes the document and
918
+ // re-opens it with the same document version but different contents. Check that we don't re-use the syntax tree of
919
+ // the previously opened document.
920
+ let testClient = try await TestSourceKitLSPClient ( )
921
+ let uri = DocumentURI ( for: . swift)
922
+ let initialPositions = testClient. openDocument (
923
+ """
924
+ 1️⃣import 2️⃣Foo
925
+ 3️⃣func 4️⃣bar() {}
926
+ """ ,
927
+ uri: uri
928
+ )
929
+ let initialTokens = try await testClient. send (
930
+ DocumentSemanticTokensRequest ( textDocument: TextDocumentIdentifier ( uri) )
931
+ )
932
+
933
+ XCTAssertEqual (
934
+ SyntaxHighlightingTokens ( lspEncodedTokens: try unwrap ( initialTokens) . data) . tokens,
935
+ [
936
+ Token ( start: initialPositions [ " 1️⃣ " ] , utf16length: 6 , kind: . keyword) ,
937
+ Token ( start: initialPositions [ " 2️⃣ " ] , utf16length: 3 , kind: . identifier) ,
938
+ Token ( start: initialPositions [ " 3️⃣ " ] , utf16length: 4 , kind: . keyword) ,
939
+ Token ( start: initialPositions [ " 4️⃣ " ] , utf16length: 3 , kind: . identifier) ,
940
+ ]
941
+ )
942
+
943
+ testClient. send ( DidCloseTextDocumentNotification ( textDocument: TextDocumentIdentifier ( uri) ) )
944
+
945
+ let reopenedPositions = testClient. openDocument (
946
+ """
947
+ 1️⃣func 2️⃣bar() {}
948
+ """ ,
949
+ uri: uri
950
+ )
951
+
952
+ let reopenedTokens = try await testClient. send (
953
+ DocumentSemanticTokensRequest ( textDocument: TextDocumentIdentifier ( uri) )
954
+ )
955
+
956
+ XCTAssertEqual (
957
+ SyntaxHighlightingTokens ( lspEncodedTokens: try unwrap ( reopenedTokens) . data) . tokens,
958
+ [
959
+ Token ( start: reopenedPositions [ " 1️⃣ " ] , utf16length: 4 , kind: . keyword) ,
960
+ Token ( start: reopenedPositions [ " 2️⃣ " ] , utf16length: 3 , kind: . identifier) ,
961
+ ]
962
+ )
963
+ }
964
+
916
965
func testClang( ) async throws {
917
966
try await assertSemanticTokens (
918
967
markedContents: """
0 commit comments