Skip to content

Commit 258b35d

Browse files
committed
test: add semantic tokens test
1 parent 5fc1646 commit 258b35d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import type { TextDocument } from '@volar/language-server';
2+
import { afterEach, expect, test } from 'vitest';
3+
import { URI } from 'vscode-uri';
4+
import { getLanguageServer, testWorkspacePath } from './server.js';
5+
6+
const openedDocuments: TextDocument[] = [];
7+
8+
afterEach(async () => {
9+
const server = await getLanguageServer();
10+
for (const document of openedDocuments) {
11+
await server.close(document.uri);
12+
}
13+
openedDocuments.length = 0;
14+
});
15+
16+
test('#5572 semantic tokens stay in sync when a git view is opened', async () => {
17+
const server = await getLanguageServer();
18+
const fileContent = `
19+
<script setup lang="ts">
20+
defineProps({
21+
foo: { type: String },
22+
});
23+
</script>
24+
`;
25+
const fileUri = URI.file(`${testWorkspacePath}/semanticTokens.vue`);
26+
27+
const document = await prepareDocument(fileUri, 'vue', fileContent);
28+
const tokensBefore = (await server.vueserver.sendSemanticTokensRequest(document.uri))!.data;
29+
30+
// simlulate open git diff view
31+
const gitUri = URI.from({ scheme: 'git', path: fileUri.path });
32+
await prepareDocument(gitUri, 'vue', fileContent.replace('foo', 'fooooooo'));
33+
34+
const tokensAfter = (await server.vueserver.sendSemanticTokensRequest(document.uri))!.data;
35+
36+
expect(tokensAfter).toEqual(tokensBefore);
37+
});
38+
39+
async function prepareDocument(uriOrFileName: string | URI, languageId: string, content: string) {
40+
const server = await getLanguageServer();
41+
const uri = typeof uriOrFileName === 'string'
42+
? URI.file(`${testWorkspacePath}/${uriOrFileName}`)
43+
: uriOrFileName;
44+
const document = await server.open(uri.toString(), languageId, content);
45+
if (openedDocuments.every(d => d.uri !== document.uri)) {
46+
openedDocuments.push(document);
47+
}
48+
return document;
49+
}

0 commit comments

Comments
 (0)