Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Volar 2.0 alpha #356

Merged
merged 16 commits into from
Dec 11, 2023
10 changes: 0 additions & 10 deletions fixtures/node16/component.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/language-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import process from 'node:process'
import {
createConnection,
startLanguageServer
startTypeScriptServer
} from '@volar/language-server/node.js'
import {plugin} from './lib/language-server-plugin.js'

process.title = 'mdx-language-server'

startLanguageServer(createConnection(), plugin)
startTypeScriptServer(createConnection(), plugin)
20 changes: 11 additions & 9 deletions packages/language-server/lib/language-server-plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import('@volar/language-server/node.js').LanguageServerPlugin} LanguageServerPlugin
* @typedef {import('@volar/language-server/node.js').ServerPlugin} ServerPlugin
*/

import assert from 'node:assert'
Expand All @@ -9,13 +9,15 @@ import {create as createTypeScriptService} from 'volar-service-typescript'
import {loadPlugins} from './configuration.js'

/**
* @type {LanguageServerPlugin}
* @type {ServerPlugin}
*/
export function plugin(initOptions, modules) {
export function plugin({modules}) {
return {
extraFileExtensions: [
{extension: 'mdx', isMixedContent: true, scriptKind: 7}
],
typescript: {
extraFileExtensions: [
{extension: 'mdx', isMixedContent: true, scriptKind: 7}
]
},

watchFileExtensions: [
'cjs',
Expand All @@ -29,11 +31,11 @@ export function plugin(initOptions, modules) {
'tsx'
],

async resolveConfig(config, ctx) {
async resolveConfig(config, env, projectContext) {
assert(modules.typescript, 'TypeScript module is missing')

const plugins = await loadPlugins(
ctx?.project?.tsConfig,
projectContext?.typescript?.configFileName,
modules.typescript
)

Expand All @@ -42,7 +44,7 @@ export function plugin(initOptions, modules) {

config.services ||= {}
config.services.markdown = createMarkdownService()
config.services.typescript = createTypeScriptService()
config.services.typescript = createTypeScriptService(modules.typescript)

return config
}
Expand Down
11 changes: 7 additions & 4 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@
},
"dependencies": {
"@mdx-js/language-service": "0.2.0",
"@volar/language-server": "~1.11.0",
"@volar/language-server": "2.0.0-alpha.3",
"load-plugin": "^5.0.0",
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
"volar-service-markdown": "0.0.17",
"volar-service-typescript": "0.0.17"
"volar-service-markdown": "0.0.20",
"volar-service-typescript": "0.0.20",
"vscode-uri": "^3.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"@types/normalize-path": "^3.0.0",
"normalize-path": "^3.0.0"
"@volar/test-utils": "2.0.0-alpha.3",
"normalize-path": "^3.0.0",
"unified": "^11.0.0"
}
}
104 changes: 37 additions & 67 deletions packages/language-server/test/completion.test.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,42 @@
/**
* @typedef {import('vscode-languageserver').ProtocolConnection} ProtocolConnection
* @typedef {import('@volar/test-utils').LanguageServerHandle} LanguageServerHandle
*/
import assert from 'node:assert/strict'
import {afterEach, beforeEach, test} from 'node:test'
import {
CompletionItemKind,
CompletionRequest,
CompletionResolveRequest,
InitializeRequest,
InsertTextFormat
} from 'vscode-languageserver'
import {
createConnection,
fixturePath,
fixtureUri,
openTextDocument,
tsdk
} from './utils.js'
import {CompletionItemKind, InsertTextFormat} from '@volar/language-server'
import {createServer, fixturePath, fixtureUri, tsdk} from './utils.js'

/** @type {ProtocolConnection} */
let connection
/** @type {LanguageServerHandle} */
let serverHandle

beforeEach(() => {
connection = createConnection()
beforeEach(async () => {
serverHandle = createServer()
await serverHandle.initialize(fixtureUri('node16'), {typescript: {tsdk}})
})

afterEach(() => {
connection.dispose()
serverHandle.connection.dispose()
})

test('support completion in ESM', async () => {
await connection.sendRequest(InitializeRequest.type, {
processId: null,
rootUri: fixtureUri('node16'),
capabilities: {},
initializationOptions: {typescript: {tsdk}}
})

const {uri} = await openTextDocument(connection, 'node16/completion.mdx')
const {uri} = await serverHandle.openTextDocument(
fixturePath('node16/completion.mdx'),
'mdx'
)
// As of TypeScript 5.3, the first request doesn’t get a response.
// This appears to be a TypeScript regression.
let result = await connection.sendRequest(CompletionRequest.type, {
position: {line: 1, character: 1},
textDocument: {uri}
let result = await serverHandle.sendCompletionRequest(uri, {
line: 1,
character: 1
})
assert.ok(result)
assert.ok('items' in result)
assert.deepEqual(result.items, [])

result = await connection.sendRequest(CompletionRequest.type, {
position: {line: 1, character: 1},
textDocument: {uri}
result = await serverHandle.sendCompletionRequest(uri, {
line: 1,
character: 1
})

assert.ok(result)
assert.ok('items' in result)
const completion = result.items.find((r) => r.label === 'Boolean')
Expand All @@ -67,7 +51,7 @@ test('support completion in ESM', async () => {
uri: fixtureUri('node16/completion.mdx.jsx')
}
},
serviceId: 'typescript',
serviceIndex: 1,
uri: fixtureUri('node16/completion.mdx'),
virtualDocumentUri: fixtureUri('node16/completion.mdx.jsx')
},
Expand All @@ -77,10 +61,7 @@ test('support completion in ESM', async () => {
sortText: '15'
})

const resolved = await connection.sendRequest(
CompletionResolveRequest.type,
completion
)
const resolved = await serverHandle.sendCompletionResolveRequest(completion)
assert.deepEqual(resolved, {
commitCharacters: ['.', ',', ';', '('],
data: {
Expand All @@ -99,17 +80,13 @@ test('support completion in ESM', async () => {
})

test('support completion in JSX', async () => {
await connection.sendRequest(InitializeRequest.type, {
processId: null,
rootUri: fixtureUri('node16'),
capabilities: {},
initializationOptions: {typescript: {tsdk}}
})

const {uri} = await openTextDocument(connection, 'node16/completion.mdx')
const result = await connection.sendRequest(CompletionRequest.type, {
position: {line: 5, character: 3},
textDocument: {uri}
const {uri} = await serverHandle.openTextDocument(
fixturePath('node16/completion.mdx'),
'mdx'
)
const result = await serverHandle.sendCompletionRequest(uri, {
line: 5,
character: 3
})

assert.ok(result)
Expand All @@ -126,7 +103,7 @@ test('support completion in JSX', async () => {
uri: fixtureUri('node16/completion.mdx.jsx')
}
},
serviceId: 'typescript',
serviceIndex: 1,
uri: fixtureUri('node16/completion.mdx'),
virtualDocumentUri: fixtureUri('node16/completion.mdx.jsx')
},
Expand All @@ -136,10 +113,7 @@ test('support completion in JSX', async () => {
sortText: '15'
})

const resolved = await connection.sendRequest(
CompletionResolveRequest.type,
completion
)
const resolved = await serverHandle.sendCompletionResolveRequest(completion)
assert.deepEqual(resolved, {
commitCharacters: ['.', ',', ';', '('],
data: {
Expand All @@ -158,17 +132,13 @@ test('support completion in JSX', async () => {
})

test('ignore completion in markdown content', async () => {
await connection.sendRequest(InitializeRequest.type, {
processId: null,
rootUri: fixtureUri('node16'),
capabilities: {},
initializationOptions: {typescript: {tsdk}}
})

const {uri} = await openTextDocument(connection, 'node16/completion.mdx')
const result = await connection.sendRequest(CompletionRequest.type, {
position: {line: 8, character: 10},
textDocument: {uri}
const {uri} = await serverHandle.openTextDocument(
fixturePath('node16/completion.mdx'),
'mdx'
)
const result = await serverHandle.sendCompletionRequest(uri, {
line: 8,
character: 10
})

assert.deepEqual(result, {isIncomplete: false, items: []})
Expand Down
Loading
Loading