Skip to content

Commit

Permalink
Update to Volar 2.3 (#446)
Browse files Browse the repository at this point in the history
Co-authored-by: Remco Haszing <remcohaszing@gmail.com>
  • Loading branch information
johnsoncodehk and remcohaszing authored Jun 10, 2024
1 parent 63f6dc0 commit 044776e
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 129 deletions.
8 changes: 8 additions & 0 deletions .changeset/friendly-toes-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@mdx-js/typescript-plugin': patch
'@mdx-js/language-service': patch
'@mdx-js/language-server': patch
'vscode-mdx': patch
---

Update to Volar 2.3.
12 changes: 6 additions & 6 deletions packages/language-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import {
createConnection,
createServer,
createTypeScriptProjectProvider,
createTypeScriptProject,
loadTsdkByPath
} from '@volar/language-server/node.js'
import {loadPlugin} from 'load-plugin'
Expand All @@ -27,6 +27,7 @@ import remarkGfm from 'remark-gfm'
import {create as createMarkdownServicePlugin} from 'volar-service-markdown'
import {create as createTypeScriptServicePlugin} from 'volar-service-typescript'
import {create as createTypeScriptSyntacticServicePlugin} from 'volar-service-typescript/lib/plugins/syntactic.js'
import {URI} from 'vscode-uri'

process.title = 'mdx-language-server'

Expand All @@ -51,12 +52,12 @@ connection.onInitialize(async (parameters) => {

return server.initialize(
parameters,
getLanguageServicePlugins(),
createTypeScriptProjectProvider(
createTypeScriptProject(
typescript,
diagnosticMessages,
(serviceEnv, {configFileName}) => getLanguagePlugins(configFileName)
)
),
getLanguageServicePlugins()
)

function getLanguageServicePlugins() {
Expand Down Expand Up @@ -168,7 +169,6 @@ connection.listen()
* @returns {Promise<Commands>}
*/
async function getCommands(uri) {
const project = await server.projects.get.call(server, uri)
const service = project.getLanguageService()
const service = await server.project.getLanguageService(URI.parse(uri))
return service.context.inject('mdxCommands')
}
8 changes: 4 additions & 4 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
},
"dependencies": {
"@mdx-js/language-service": "0.5.6",
"@volar/language-server": "~2.2.0",
"@volar/language-server": "~2.3.0",
"load-plugin": "^6.0.0",
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
"volar-service-markdown": "0.0.47",
"volar-service-typescript": "0.0.47",
"volar-service-markdown": "0.0.51",
"volar-service-typescript": "0.0.51",
"vscode-uri": "^3.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"@volar/test-utils": "~2.2.0",
"@volar/test-utils": "~2.3.0",
"unified": "^11.0.0"
}
}
67 changes: 47 additions & 20 deletions packages/language-server/test/completion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import assert from 'node:assert/strict'
import {afterEach, beforeEach, test} from 'node:test'
import {CompletionItemKind, InsertTextFormat} from '@volar/language-server'
import {URI} from 'vscode-uri'
import {createServer, fixturePath, fixtureUri, tsdk} from './utils.js'

/** @type {LanguageServerHandle} */
Expand Down Expand Up @@ -36,20 +37,29 @@ test('support completion in ESM', async () => {
assert.deepEqual(completion, {
commitCharacters: ['.', ',', ';', '('],
data: {
embeddedDocumentUri:
'volar-embedded-content://jsx/' +
encodeURIComponent(fixtureUri('node16/completion.mdx')),
embeddedDocumentUri: String(
URI.from({
scheme: 'volar-embedded-content',
authority: 'jsx',
path: '/' + encodeURIComponent(fixtureUri('node16/completion.mdx'))
})
),
original: {
data: {
fileName: fixturePath('node16/completion.mdx'),
offset: 81,
originalItem: {name: 'Boolean'},
uri:
'volar-embedded-content://jsx/' +
encodeURIComponent(fixtureUri('node16/completion.mdx'))
uri: String(
URI.from({
scheme: 'volar-embedded-content',
authority: 'jsx',
path:
'/' + encodeURIComponent(fixtureUri('node16/completion.mdx'))
})
)
}
},
serviceIndex: 2,
pluginIndex: 2,
uri: fixtureUri('node16/completion.mdx')
},
insertTextFormat: InsertTextFormat.PlainText,
Expand All @@ -65,9 +75,13 @@ test('support completion in ESM', async () => {
fileName: fixturePath('node16/completion.mdx'),
offset: 81,
originalItem: {name: 'Boolean'},
uri:
'volar-embedded-content://jsx/' +
encodeURIComponent(fixtureUri('node16/completion.mdx'))
uri: String(
URI.from({
scheme: 'volar-embedded-content',
authority: 'jsx',
path: '/' + encodeURIComponent(fixtureUri('node16/completion.mdx'))
})
)
},
detail: 'interface Boolean\nvar Boolean: BooleanConstructor',
documentation: {kind: 'markdown', value: ''},
Expand Down Expand Up @@ -98,20 +112,29 @@ test('support completion in JSX', async () => {
assert.deepEqual(completion, {
commitCharacters: ['.', ',', ';', '('],
data: {
embeddedDocumentUri:
'volar-embedded-content://jsx/' +
encodeURIComponent(fixtureUri('node16/completion.mdx')),
embeddedDocumentUri: String(
URI.from({
scheme: 'volar-embedded-content',
authority: 'jsx',
path: '/' + encodeURIComponent(fixtureUri('node16/completion.mdx'))
})
),
original: {
data: {
fileName: fixturePath('node16/completion.mdx'),
offset: 119,
originalItem: {name: 'Boolean'},
uri:
'volar-embedded-content://jsx/' +
encodeURIComponent(fixtureUri('node16/completion.mdx'))
uri: String(
URI.from({
scheme: 'volar-embedded-content',
authority: 'jsx',
path:
'/' + encodeURIComponent(fixtureUri('node16/completion.mdx'))
})
)
}
},
serviceIndex: 2,
pluginIndex: 2,
uri: fixtureUri('node16/completion.mdx')
},
insertTextFormat: InsertTextFormat.PlainText,
Expand All @@ -127,9 +150,13 @@ test('support completion in JSX', async () => {
fileName: fixturePath('node16/completion.mdx'),
offset: 119,
originalItem: {name: 'Boolean'},
uri:
'volar-embedded-content://jsx/' +
encodeURIComponent(fixtureUri('node16/completion.mdx'))
uri: String(
URI.from({
scheme: 'volar-embedded-content',
authority: 'jsx',
path: '/' + encodeURIComponent(fixtureUri('node16/completion.mdx'))
})
)
},
detail: 'interface Boolean\nvar Boolean: BooleanConstructor',
documentation: {kind: 'markdown', value: ''},
Expand Down
53 changes: 37 additions & 16 deletions packages/language-server/test/diagnostics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import assert from 'node:assert/strict'
import {afterEach, beforeEach, test} from 'node:test'
import {URI} from 'vscode-uri'
import {createServer, fixturePath, fixtureUri, tsdk} from './utils.js'

/** @type {LanguageServerHandle} */
Expand Down Expand Up @@ -35,12 +36,17 @@ test('parse errors', async () => {
href: 'https://github.com/micromark/micromark-extension-mdxjs-esm#could-not-parse-importexports-with-acorn'
},
data: {
documentUri:
'volar-embedded-content://mdx/' +
encodeURIComponent(fixtureUri('node16/syntax-error.mdx')),
documentUri: String(
URI.from({
scheme: 'volar-embedded-content',
authority: 'mdx',
path:
'/' + encodeURIComponent(fixtureUri('node16/syntax-error.mdx'))
})
),
isFormat: false,
original: {},
serviceIndex: 1,
pluginIndex: 1,
uri: fixtureUri('node16/syntax-error.mdx'),
version: 0
},
Expand Down Expand Up @@ -75,12 +81,17 @@ test('type errors', async () => {
{
code: 2568,
data: {
documentUri:
'volar-embedded-content://jsx/' +
encodeURIComponent(fixtureUri('node16/type-errors.mdx')),
documentUri: String(
URI.from({
scheme: 'volar-embedded-content',
authority: 'jsx',
path:
'/' + encodeURIComponent(fixtureUri('node16/type-errors.mdx'))
})
),
isFormat: false,
original: {},
serviceIndex: 2,
pluginIndex: 2,
uri: fixtureUri('node16/type-errors.mdx'),
version: 0
},
Expand All @@ -96,12 +107,17 @@ test('type errors', async () => {
{
code: 2568,
data: {
documentUri:
'volar-embedded-content://jsx/' +
encodeURIComponent(fixtureUri('node16/type-errors.mdx')),
documentUri: String(
URI.from({
scheme: 'volar-embedded-content',
authority: 'jsx',
path:
'/' + encodeURIComponent(fixtureUri('node16/type-errors.mdx'))
})
),
isFormat: false,
original: {},
serviceIndex: 2,
pluginIndex: 2,
uri: fixtureUri('node16/type-errors.mdx'),
version: 0
},
Expand Down Expand Up @@ -155,12 +171,17 @@ test('provided components', async () => {
{
code: 2741,
data: {
documentUri:
'volar-embedded-content://jsx/' +
encodeURIComponent(fixtureUri('provide/solar-system.mdx')),
documentUri: String(
URI.from({
scheme: 'volar-embedded-content',
authority: 'jsx',
path:
'/' + encodeURIComponent(fixtureUri('provide/solar-system.mdx'))
})
),
isFormat: false,
original: {},
serviceIndex: 2,
pluginIndex: 2,
uri: fixtureUri('provide/solar-system.mdx'),
version: 0
},
Expand Down
15 changes: 11 additions & 4 deletions packages/language-server/test/document-link.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import assert from 'node:assert/strict'
import {afterEach, beforeEach, test} from 'node:test'
import {URI} from 'vscode-uri'
import {createServer, fixturePath, fixtureUri, tsdk} from './utils.js'

/** @type {LanguageServerHandle} */
Expand Down Expand Up @@ -33,7 +34,11 @@ test('resolve markdown link references', async () => {
end: {line: 0, character: 12}
},
tooltip: 'Go to link definition',
target: fixtureUri('node16/link-reference.mdx#L3,8').replace('%3A', ':'),
target: String(
URI.parse(fixtureUri('node16/link-reference.mdx')).with({
fragment: 'L3,8'
})
),
data: {
uri: fixtureUri('node16/link-reference.mdx'),
original: {
Expand All @@ -46,7 +51,9 @@ test('resolve markdown link references', async () => {
resource: {
$mid: 1,
authority: 'md',
path: '/' + fixtureUri('node16/link-reference.mdx'),
path:
'/' +
encodeURIComponent(fixtureUri('node16/link-reference.mdx')),
scheme: 'volar-embedded-content'
},
range: {
Expand All @@ -65,7 +72,7 @@ test('resolve markdown link references', async () => {
href: {kind: 2, ref: 'mdx'}
}
},
serviceIndex: 0
pluginIndex: 0
}
},
{
Expand All @@ -74,7 +81,7 @@ test('resolve markdown link references', async () => {
data: {
uri: fixtureUri('node16/link-reference.mdx'),
original: {},
serviceIndex: 0
pluginIndex: 0
}
}
])
Expand Down
12 changes: 8 additions & 4 deletions packages/language-server/test/initialize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ test('initialize', async () => {
{typescript: {enabled: true, tsdk}}
)
assert.deepEqual(initializeResponse, {
autoInsertion: {
configurationSections: [
'javascript.autoClosingTags',
'typescript.autoClosingTags'
],
triggerCharacters: ['>', '>']
},
capabilities: {
callHierarchyProvider: true,
codeActionProvider: {
Expand All @@ -38,8 +45,6 @@ test('initialize', async () => {
],
resolveProvider: true
},
codeLensProvider: {resolveProvider: true},
colorProvider: true,
completionProvider: {
resolveProvider: true,
triggerCharacters: ['.', '/', '#', '"', "'", '`', '<', '@', ' ', '*']
Expand All @@ -57,8 +62,7 @@ test('initialize', async () => {
foldingRangeProvider: true,
hoverProvider: true,
implementationProvider: true,
inlayHintProvider: {resolveProvider: true},
linkedEditingRangeProvider: true,
inlayHintProvider: {},
referencesProvider: true,
renameProvider: {prepareProvider: true},
selectionRangeProvider: true,
Expand Down
Loading

0 comments on commit 044776e

Please sign in to comment.