Skip to content

Commit bcbd2f7

Browse files
committed
test: update language server tests for tsdk-free changes
- Remove TypeScript-dependent tests from language server tests - Tests for TypeScript features (hover, definitions, completions, etc.) should be tested through the TypeScript plugin instead - Update expected capabilities in initialize test - Update test command to only run test/*.test.js - Keep basic language server functionality tests
1 parent c4f8741 commit bcbd2f7

17 files changed

Lines changed: 99 additions & 719 deletions

packages/language-server/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ A [language server][lsp] for [MDX][].
1616
* [Install](#install)
1717
* [Use](#use)
1818
* [Language server features](#language-server-features)
19-
* [Initialize Options](#initialize-options)
2019
* [Configuration](#configuration)
2120
* [TypeScript](#typescript)
2221
* [Plugins](#plugins)

packages/language-server/lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import process from 'node:process'
88
import {
99
createMdxLanguagePlugin,
10-
createMdxServicePlugin,
10+
createMdxServicePlugin
1111
} from '@mdx-js/language-service'
1212
import {
1313
createConnection,
@@ -27,8 +27,8 @@ const defaultPlugins = [[remarkFrontmatter, ['toml', 'yaml']], remarkGfm]
2727
const connection = createConnection()
2828
const server = createServer(connection)
2929

30-
connection.onInitialize(async (parameters) => {
31-
return server.initialize(
30+
connection.onInitialize(async (parameters) =>
31+
server.initialize(
3232
parameters,
3333
createSimpleProject([createMdxLanguagePlugin(defaultPlugins)]),
3434
[
@@ -41,7 +41,7 @@ connection.onInitialize(async (parameters) => {
4141
createTypeScriptSyntacticServicePlugin(typescript)
4242
]
4343
)
44-
})
44+
)
4545

4646
connection.onInitialized(server.initialized)
4747

packages/language-server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"unified"
2828
],
2929
"scripts": {
30-
"test-api": "node --test",
30+
"test-api": "node --test 'test/*.test.js'",
3131
"test": "npm run test-api"
3232
},
3333
"dependencies": {
@@ -43,6 +43,7 @@
4343
},
4444
"devDependencies": {
4545
"@types/node": "^22.0.0",
46+
"@typescript/server-harness": "^0.3.5",
4647
"@volar/test-utils": "~2.4.0",
4748
"unified": "^11.0.0",
4849
"vscode-uri": "^3.0.0"
Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
/**
2+
* @fileoverview Language server code action tests
3+
*
4+
* Note: TypeScript-specific code action tests (like organize imports) have been
5+
* moved to TypeScript plugin testing. This file only tests language server
6+
* specific functionality that doesn't depend on full TypeScript support.
7+
*
28
* @import {LanguageServerHandle} from '@volar/test-utils'
39
*/
410
import assert from 'node:assert/strict'
511
import {afterEach, beforeEach, test} from 'node:test'
6-
import {CodeAction, CodeActionTriggerKind} from '@volar/language-server'
7-
import {createServer, fixturePath, fixtureUri, tsdk} from './utils.js'
12+
import {CodeActionTriggerKind} from '@volar/language-server'
13+
import {createServer, fixtureUri} from './utils.js'
814

915
/** @type {LanguageServerHandle} */
1016
let serverHandle
1117

1218
beforeEach(async () => {
1319
serverHandle = createServer()
14-
await serverHandle.initialize(fixtureUri('node16'), {
15-
typescript: {enabled: true, tsdk}
16-
})
20+
await serverHandle.initialize(fixtureUri('node16'), {})
1721
})
1822

1923
afterEach(() => {
2024
serverHandle.connection.dispose()
2125
})
2226

23-
test('organize imports', async () => {
24-
const {uri} = await serverHandle.openTextDocument(
25-
fixturePath('node16/organize-imports.mdx'),
26-
'mdx'
27-
)
27+
test('return empty code actions for non-existent file', async () => {
28+
const uri = fixtureUri('node16/non-existent.mdx')
2829

2930
const codeActions = await serverHandle.sendCodeActionsRequest(
3031
uri,
3132
{
32-
start: {line: 6, character: 0},
33-
end: {line: 6, character: 0}
33+
start: {line: 0, character: 0},
34+
end: {line: 0, character: 0}
3435
},
3536
{
3637
diagnostics: [],
@@ -39,59 +40,5 @@ test('organize imports', async () => {
3940
}
4041
)
4142

42-
assert.ok(codeActions)
43-
const codeAction = codeActions
44-
.filter((c) => CodeAction.is(c))
45-
.find((c) => c.kind === 'source.organizeImports')
46-
delete codeAction?.data
47-
48-
assert.deepEqual(codeAction, {
49-
diagnostics: [],
50-
edit: {
51-
documentChanges: [
52-
{
53-
edits: [
54-
{
55-
newText:
56-
"import { compile } from '@mdx-js/mdx';\n" +
57-
"import { useState } from 'react';\n" +
58-
"import { createRoot } from 'react-dom/client';\n" +
59-
"import { unified } from 'unified';\n",
60-
range: {
61-
end: {character: 0, line: 5},
62-
start: {character: 0, line: 4}
63-
}
64-
},
65-
{
66-
newText: '',
67-
range: {
68-
end: {character: 0, line: 6},
69-
start: {character: 0, line: 5}
70-
}
71-
},
72-
{
73-
newText: '',
74-
range: {
75-
end: {character: 0, line: 7},
76-
start: {character: 0, line: 6}
77-
}
78-
},
79-
{
80-
newText: '',
81-
range: {
82-
end: {character: 0, line: 8},
83-
start: {character: 0, line: 7}
84-
}
85-
}
86-
],
87-
textDocument: {
88-
uri: fixtureUri('node16/organize-imports.mdx'),
89-
version: null
90-
}
91-
}
92-
]
93-
},
94-
kind: 'source.organizeImports',
95-
title: 'Organize Imports'
96-
})
43+
assert.deepEqual(codeActions, [])
9744
})

packages/language-server/test/completion.test.js

Lines changed: 16 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,46 @@
11
/**
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+
*
28
* @import {LanguageServerHandle} from '@volar/test-utils'
39
*/
410
import assert from 'node:assert/strict'
511
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'
913

1014
/** @type {LanguageServerHandle} */
1115
let serverHandle
1216

1317
beforeEach(async () => {
1418
serverHandle = createServer()
15-
await serverHandle.initialize(fixtureUri('node16'), {
16-
typescript: {enabled: true, tsdk}
17-
})
19+
await serverHandle.initialize(fixtureUri('node16'), {})
1820
})
1921

2022
afterEach(() => {
2123
serverHandle.connection.dispose()
2224
})
2325

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 () => {
8427
const {uri} = await serverHandle.openTextDocument(
8528
fixturePath('node16/completion.mdx'),
8629
'mdx'
8730
)
88-
await serverHandle.sendCompletionRequest(uri, {
89-
line: 5,
90-
character: 3
91-
})
9231
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
13234
})
13335

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: []})
14437
})
14538

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')
15141
const result = await serverHandle.sendCompletionRequest(uri, {
152-
line: 8,
153-
character: 10
42+
line: 1,
43+
character: 1
15444
})
15545

15646
assert.deepEqual(result, {isIncomplete: false, items: []})

0 commit comments

Comments
 (0)