Skip to content

Commit 30384a0

Browse files
committed
fix: update support for new volar
1 parent 2a39444 commit 30384a0

File tree

4 files changed

+56
-24
lines changed

4 files changed

+56
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"@types/mocha": "^9.1.1",
147147
"@types/pluralize": "^0.0.29",
148148
"@volar/language-server": "1.3.0-alpha.3",
149-
"@volar/language-service": "1.3.0-alpha.3",
149+
"@volar/language-service": "1.5.0",
150150
"@volar/vue-language-core": "^1.2.0-patch.2",
151151
"@vscode/emmet-helper": "^2.8.4",
152152
"@vscode/test-electron": "^2.1.5",

pnpm-lock.yaml

Lines changed: 36 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vueVolarSupport.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,24 @@ export default () => {
66
if (process.env.PLATFORM !== 'node') return
77
const handler = () => {
88
const config = vscode.workspace.getConfiguration('')
9-
if (
10-
!getExtensionSetting('enableVueSupport') ||
11-
!vscode.extensions.getExtension('Vue.volar') ||
12-
isConfigValueChanged('volar.vueserver.configFilePath')
13-
) {
9+
const VOLAR_CONFIG_FILE_SETTING = 'vue.server.configFilePath'
10+
if (!getExtensionSetting('enableVueSupport') || !vscode.extensions.getExtension('Vue.volar') || isConfigValueChanged(VOLAR_CONFIG_FILE_SETTING)) {
1411
return
1512
}
1613

17-
void config.update('volar.vueserver.configFilePath', extensionCtx.asAbsolutePath('./volarConfig.js'), vscode.ConfigurationTarget.Global)
14+
void config.update(VOLAR_CONFIG_FILE_SETTING, extensionCtx.asAbsolutePath('./volarConfig.js'), vscode.ConfigurationTarget.Global)
1815
}
1916

2017
handler()
2118
watchExtensionSettings(['enableVueSupport'], handler)
2219
vscode.extensions.onDidChange(handler)
2320
}
2421

25-
const isConfigValueChanged = (id: string) => {
22+
const isConfigValueChanged = (settingId: string) => {
2623
if (process.env.PLATFORM !== 'web') {
2724
const config = vscode.workspace.getConfiguration('')
28-
const userValue = config.get<string>(id)
29-
if (userValue === config.inspect(id)!.defaultValue) return false
25+
const userValue = config.get<string>(settingId)
26+
if (userValue === config.inspect(settingId)!.defaultValue) return false
3027
// means that value was set by us programmatically, let's update it
3128
// eslint-disable-next-line @typescript-eslint/no-require-imports
3229
if (userValue?.startsWith(require('path').join(extensionCtx.extensionPath, '../..'))) return false

typescript/src/volarConfig.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// will be required from ./node_modules/typescript-essential-plugins/index.js
33
const originalPluginFactory = require('typescript-essential-plugins')
44

5-
const plugin = (context => {
5+
const plugin = ((context, { typescript: tsModule } = {}) => {
6+
if (!context) throw new Error('Not recieve context')
67
const { typescript } = context
7-
let configurationHost = context.configurationHost!
8-
configurationHost ??= context['env'].configurationHost
8+
let configurationHost = context.env
9+
if (context['configurationHost']!) configurationHost = context['configurationHost']!
910
const patchConfig = config => {
1011
return {
1112
...config,
@@ -17,13 +18,14 @@ const plugin = (context => {
1718
}
1819

1920
if (typescript && configurationHost) {
21+
const ts = tsModule ?? typescript['module']
2022
const plugin = originalPluginFactory({
21-
typescript: typescript.module,
23+
typescript: ts,
2224
})
2325
// todo support vue-specific settings
2426
const originalLsMethods = { ...typescript.languageService }
2527

26-
void configurationHost.getConfiguration<any>('tsEssentialPlugins').then(_configuration => {
28+
void configurationHost.getConfiguration!<any>('tsEssentialPlugins').then(_configuration => {
2729
// if (typescript.languageService[thisPluginMarker]) return
2830
const config = patchConfig(_configuration)
2931
if (!config.enablePlugin) return
@@ -39,8 +41,8 @@ const plugin = (context => {
3941
}
4042
})
4143

42-
configurationHost.onDidChangeConfiguration(() => {
43-
void configurationHost.getConfiguration<any>('tsEssentialPlugins').then(config => {
44+
configurationHost.onDidChangeConfiguration!(() => {
45+
void configurationHost.getConfiguration!<any>('tsEssentialPlugins').then(config => {
4446
config = patchConfig(config)
4547
plugin.onConfigurationChanged?.(config)
4648
// temporary workaround
@@ -54,17 +56,17 @@ const plugin = (context => {
5456
console.warn('Failed to activate tsEssentialPlugins, because of no typescript or configurationHost context')
5557
}
5658
return {}
57-
}) satisfies import('@volar/language-service').LanguageServicePlugin
59+
}) satisfies import('@volar/language-service').Service
5860

5961
module.exports = {
6062
plugins: [
61-
c => {
63+
(...args) => {
6264
try {
63-
return plugin(c)
65+
return plugin(...(args as [any]))
6466
} catch (err) {
6567
console.log('TS Essentials error', err)
6668
return {}
6769
}
6870
},
6971
],
70-
}
72+
} /* satisfies import('@volar/language-service').ServiceContext */

0 commit comments

Comments
 (0)