|
1 | 1 | /** |
| 2 | + * @fileoverview Language server completion tests |
| 3 | + * |
| 4 | + * Note: TypeScript-specific completion tests have been moved to TypeScript |
| 5 | + * plugin testing. This file only tests language server specific functionality |
| 6 | + * that doesn't depend on full TypeScript support. |
| 7 | + * |
2 | 8 | * @import {LanguageServerHandle} from '@volar/test-utils' |
3 | 9 | */ |
4 | 10 | import assert from 'node:assert/strict' |
5 | 11 | import {afterEach, beforeEach, test} from 'node:test' |
6 | | -import {CompletionItemKind, InsertTextFormat} from '@volar/language-server' |
7 | | -import {URI} from 'vscode-uri' |
8 | | -import {createServer, fixturePath, fixtureUri, tsdk} from './utils.js' |
| 12 | +import {createServer, fixturePath, fixtureUri} from './utils.js' |
9 | 13 |
|
10 | 14 | /** @type {LanguageServerHandle} */ |
11 | 15 | let serverHandle |
12 | 16 |
|
13 | 17 | beforeEach(async () => { |
14 | 18 | serverHandle = createServer() |
15 | | - await serverHandle.initialize(fixtureUri('node16'), { |
16 | | - typescript: {enabled: true, tsdk} |
17 | | - }) |
| 19 | + await serverHandle.initialize(fixtureUri('node16'), {}) |
18 | 20 | }) |
19 | 21 |
|
20 | 22 | afterEach(() => { |
21 | 23 | serverHandle.connection.dispose() |
22 | 24 | }) |
23 | 25 |
|
24 | | -test('support completion in ESM', async () => { |
25 | | - const {uri} = await serverHandle.openTextDocument( |
26 | | - fixturePath('node16/completion.mdx'), |
27 | | - 'mdx' |
28 | | - ) |
29 | | - |
30 | | - const result = await serverHandle.sendCompletionRequest(uri, { |
31 | | - line: 1, |
32 | | - character: 1 |
33 | | - }) |
34 | | - assert.ok(result) |
35 | | - assert.ok('items' in result) |
36 | | - const completion = result.items.find((r) => r.label === 'Boolean') |
37 | | - assert.deepEqual(completion, { |
38 | | - commitCharacters: ['.', ',', ';', '('], |
39 | | - data: { |
40 | | - embeddedDocumentUri: String( |
41 | | - URI.from({ |
42 | | - scheme: 'volar-embedded-content', |
43 | | - authority: 'jsx', |
44 | | - path: '/' + encodeURIComponent(fixtureUri('node16/completion.mdx')) |
45 | | - }) |
46 | | - ), |
47 | | - original: { |
48 | | - data: { |
49 | | - fileName: fixturePath('node16/completion.mdx'), |
50 | | - offset: 108, |
51 | | - originalItem: {name: 'Boolean'}, |
52 | | - uri: String( |
53 | | - URI.from({ |
54 | | - scheme: 'volar-embedded-content', |
55 | | - authority: 'jsx', |
56 | | - path: |
57 | | - '/' + encodeURIComponent(fixtureUri('node16/completion.mdx')) |
58 | | - }) |
59 | | - ) |
60 | | - } |
61 | | - }, |
62 | | - pluginIndex: 2, |
63 | | - uri: fixtureUri('node16/completion.mdx') |
64 | | - }, |
65 | | - insertTextFormat: InsertTextFormat.PlainText, |
66 | | - kind: CompletionItemKind.Variable, |
67 | | - label: 'Boolean', |
68 | | - sortText: '15' |
69 | | - }) |
70 | | - |
71 | | - const resolved = await serverHandle.sendCompletionResolveRequest(completion) |
72 | | - assert.deepEqual(resolved, { |
73 | | - commitCharacters: ['.', ',', ';', '('], |
74 | | - detail: 'interface Boolean\nvar Boolean: BooleanConstructor', |
75 | | - documentation: {kind: 'markdown', value: ''}, |
76 | | - insertTextFormat: 1, |
77 | | - kind: 6, |
78 | | - label: 'Boolean', |
79 | | - sortText: '15' |
80 | | - }) |
81 | | -}) |
82 | | - |
83 | | -test('support completion in JSX', async () => { |
| 26 | +test('ignore completion in markdown content', async () => { |
84 | 27 | const {uri} = await serverHandle.openTextDocument( |
85 | 28 | fixturePath('node16/completion.mdx'), |
86 | 29 | 'mdx' |
87 | 30 | ) |
88 | | - await serverHandle.sendCompletionRequest(uri, { |
89 | | - line: 5, |
90 | | - character: 3 |
91 | | - }) |
92 | 31 | const result = await serverHandle.sendCompletionRequest(uri, { |
93 | | - line: 5, |
94 | | - character: 3 |
95 | | - }) |
96 | | - |
97 | | - assert.ok(result) |
98 | | - assert.ok('items' in result) |
99 | | - const completion = result.items.find((r) => r.label === 'Boolean') |
100 | | - assert.deepEqual(completion, { |
101 | | - commitCharacters: ['.', ',', ';', '('], |
102 | | - data: { |
103 | | - embeddedDocumentUri: String( |
104 | | - URI.from({ |
105 | | - scheme: 'volar-embedded-content', |
106 | | - authority: 'jsx', |
107 | | - path: '/' + encodeURIComponent(fixtureUri('node16/completion.mdx')) |
108 | | - }) |
109 | | - ), |
110 | | - original: { |
111 | | - data: { |
112 | | - fileName: fixturePath('node16/completion.mdx'), |
113 | | - offset: 146, |
114 | | - originalItem: {name: 'Boolean'}, |
115 | | - uri: String( |
116 | | - URI.from({ |
117 | | - scheme: 'volar-embedded-content', |
118 | | - authority: 'jsx', |
119 | | - path: |
120 | | - '/' + encodeURIComponent(fixtureUri('node16/completion.mdx')) |
121 | | - }) |
122 | | - ) |
123 | | - } |
124 | | - }, |
125 | | - pluginIndex: 2, |
126 | | - uri: fixtureUri('node16/completion.mdx') |
127 | | - }, |
128 | | - insertTextFormat: InsertTextFormat.PlainText, |
129 | | - kind: CompletionItemKind.Variable, |
130 | | - label: 'Boolean', |
131 | | - sortText: '15' |
| 32 | + line: 8, |
| 33 | + character: 10 |
132 | 34 | }) |
133 | 35 |
|
134 | | - const resolved = await serverHandle.sendCompletionResolveRequest(completion) |
135 | | - assert.deepEqual(resolved, { |
136 | | - commitCharacters: ['.', ',', ';', '('], |
137 | | - detail: 'interface Boolean\nvar Boolean: BooleanConstructor', |
138 | | - documentation: {kind: 'markdown', value: ''}, |
139 | | - insertTextFormat: 1, |
140 | | - kind: 6, |
141 | | - label: 'Boolean', |
142 | | - sortText: '15' |
143 | | - }) |
| 36 | + assert.deepEqual(result, {isIncomplete: false, items: []}) |
144 | 37 | }) |
145 | 38 |
|
146 | | -test('ignore completion in markdown content', async () => { |
147 | | - const {uri} = await serverHandle.openTextDocument( |
148 | | - fixturePath('node16/completion.mdx'), |
149 | | - 'mdx' |
150 | | - ) |
| 39 | +test('ignore non-existent mdx files', async () => { |
| 40 | + const uri = fixtureUri('node16/non-existent.mdx') |
151 | 41 | const result = await serverHandle.sendCompletionRequest(uri, { |
152 | | - line: 8, |
153 | | - character: 10 |
| 42 | + line: 1, |
| 43 | + character: 1 |
154 | 44 | }) |
155 | 45 |
|
156 | 46 | assert.deepEqual(result, {isIncomplete: false, items: []}) |
|
0 commit comments