Skip to content

Commit f49e1b8

Browse files
feat: redesign additional extensions, VitePress, PetiteVue support (#4321)
1 parent 80118ac commit f49e1b8

File tree

20 files changed

+264
-303
lines changed

20 files changed

+264
-303
lines changed

extensions/vscode/package.json

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@
9090
{
9191
"name": "typescript-vue-plugin-bundle",
9292
"enableForWorkspaceTypeScriptVersions": true,
93-
"configNamespace": "typescript",
94-
"languages": [
95-
"vue"
96-
]
93+
"configNamespace": "typescript"
9794
}
9895
],
9996
"grammars": [
@@ -236,32 +233,20 @@
236233
],
237234
"description": "Vue language server only handles CSS and HTML language support, and tsserver takes over TS language support via TS plugin."
238235
},
236+
"vue.server.includeLanguages": {
237+
"type": "array",
238+
"items": {
239+
"type": "string"
240+
},
241+
"default": [
242+
"vue"
243+
]
244+
},
239245
"vue.server.maxFileSize": {
240246
"type": "number",
241247
"default": 20971520,
242248
"description": "Maximum file size for Vue Language Server to load. (default: 20MB)"
243249
},
244-
"vue.server.petiteVue.supportHtmlFile": {
245-
"type": "boolean",
246-
"default": false
247-
},
248-
"vue.server.vitePress.supportMdFile": {
249-
"type": "boolean",
250-
"default": false
251-
},
252-
"vue.server.diagnosticModel": {
253-
"type": "string",
254-
"default": "push",
255-
"enum": [
256-
"push",
257-
"pull"
258-
],
259-
"enumDescriptions": [
260-
"Diagnostic push by language server.",
261-
"Diagnostic pull by language client."
262-
],
263-
"description": "Diagnostic update model."
264-
},
265250
"vue.server.maxOldSpaceSize": {
266251
"type": [
267252
"number",
@@ -270,14 +255,6 @@
270255
"default": null,
271256
"description": "Set --max-old-space-size option on server process. If you have problem on frequently \"Request textDocument/** failed.\" error, try setting higher memory(MB) on it."
272257
},
273-
"vue.server.additionalExtensions": {
274-
"type": "array",
275-
"items": {
276-
"type": "string"
277-
},
278-
"default": [],
279-
"description": "List any additional file extensions that should be processed as Vue files (requires restart)."
280-
},
281258
"vue.doctor.status": {
282259
"type": "boolean",
283260
"default": true,
@@ -290,6 +267,9 @@
290267
},
291268
"vue.splitEditors.layout.left": {
292269
"type": "array",
270+
"items": {
271+
"type": "string"
272+
},
293273
"default": [
294274
"script",
295275
"scriptSetup",
@@ -298,6 +278,9 @@
298278
},
299279
"vue.splitEditors.layout.right": {
300280
"type": "array",
281+
"items": {
282+
"type": "string"
283+
},
301284
"default": [
302285
"template",
303286
"customBlocks"

extensions/vscode/src/common.ts

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let client: lsp.BaseLanguageClient;
1515
type CreateLanguageClient = (
1616
id: string,
1717
name: string,
18-
langs: lsp.DocumentFilter[],
18+
langs: lsp.DocumentSelector,
1919
initOptions: VueInitializationOptions,
2020
port: number,
2121
outputChannel: vscode.OutputChannel,
@@ -27,11 +27,7 @@ export async function activate(context: vscode.ExtensionContext, createLc: Creat
2727
tryActivate();
2828

2929
function tryActivate() {
30-
if (
31-
vscode.window.visibleTextEditors.some(editor => editor.document.languageId === 'vue')
32-
|| (config.server.vitePress.supportMdFile && vscode.window.visibleTextEditors.some(editor => editor.document.languageId === 'markdown'))
33-
|| (config.server.petiteVue.supportHtmlFile && vscode.window.visibleTextEditors.some(editor => editor.document.languageId === 'html'))
34-
) {
30+
if (vscode.window.visibleTextEditors.some(editor => config.server.includeLanguages.includes(editor.document.languageId))) {
3531
doActivate(context, createLc);
3632
stopCheck.dispose();
3733
}
@@ -210,30 +206,22 @@ function getCurrentHybridModeStatus(report = false) {
210206

211207
async function doActivate(context: vscode.ExtensionContext, createLc: CreateLanguageClient) {
212208

209+
vscode.commands.executeCommand('setContext', 'vue.activated', true);
210+
213211
getCurrentHybridModeStatus(true);
214212

215213
const outputChannel = vscode.window.createOutputChannel('Vue Language Server');
216-
217-
vscode.commands.executeCommand('setContext', 'vue.activated', true);
214+
const selectors = config.server.includeLanguages;
218215

219216
client = createLc(
220217
'vue',
221218
'Vue',
222-
getDocumentSelector(),
219+
selectors,
223220
await getInitializationOptions(context, enabledHybridMode),
224221
6009,
225222
outputChannel
226223
);
227224

228-
const selectors: vscode.DocumentFilter[] = [{ language: 'vue' }];
229-
230-
if (config.server.petiteVue.supportHtmlFile) {
231-
selectors.push({ language: 'html' });
232-
}
233-
if (config.server.vitePress.supportMdFile) {
234-
selectors.push({ language: 'markdown' });
235-
}
236-
237225
activateConfigWatcher();
238226
activateRestartRequest();
239227

@@ -410,6 +398,16 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
410398
);
411399
}
412400
}
401+
else if (e.affectsConfiguration('vue.server')) {
402+
if (enabledHybridMode) {
403+
if (e.affectsConfiguration('vue.server.includeLanguages')) {
404+
requestReloadVscode('Please reload VSCode to apply the new language settings.');
405+
}
406+
}
407+
else {
408+
vscode.commands.executeCommand('vue.action.restartServer', false);
409+
}
410+
}
413411
else if (e.affectsConfiguration('vue')) {
414412
vscode.commands.executeCommand('vue.action.restartServer', false);
415413
}
@@ -434,25 +432,12 @@ export function deactivate(): Thenable<any> | undefined {
434432
return client?.stop();
435433
}
436434

437-
export function getDocumentSelector(): lsp.DocumentFilter[] {
438-
const selectors: lsp.DocumentFilter[] = [];
439-
selectors.push({ language: 'vue' });
440-
if (config.server.petiteVue.supportHtmlFile) {
441-
selectors.push({ language: 'html' });
442-
}
443-
if (config.server.vitePress.supportMdFile) {
444-
selectors.push({ language: 'markdown' });
445-
}
446-
return selectors;
447-
}
448-
449435
async function getInitializationOptions(
450436
context: vscode.ExtensionContext,
451437
hybridMode: boolean,
452438
): Promise<VueInitializationOptions> {
453439
return {
454-
// volar
455-
diagnosticModel: config.server.diagnosticModel === 'pull' ? DiagnosticModel.Pull : DiagnosticModel.Push,
440+
diagnosticModel: enabledHybridMode ? DiagnosticModel.Pull : DiagnosticModel.Push,
456441
typescript: { tsdk: (await lsp.getTsdk(context)).tsdk },
457442
maxFileSize: config.server.maxFileSize,
458443
semanticTokensLegend: {
@@ -461,11 +446,6 @@ async function getInitializationOptions(
461446
},
462447
vue: {
463448
hybridMode,
464-
additionalExtensions: [
465-
...config.server.additionalExtensions,
466-
...!config.server.petiteVue.supportHtmlFile ? [] : ['html'],
467-
...!config.server.vitePress.supportMdFile ? [] : ['md'],
468-
],
469449
},
470450
};
471451
};

extensions/vscode/src/config.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,10 @@ export const config = {
1616
return _config().get('doctor')!;
1717
},
1818
get server(): Readonly<{
19+
includeLanguages: string[];
1920
hybridMode: 'auto' | 'typeScriptPluginOnly' | boolean;
2021
maxOldSpaceSize: number;
2122
maxFileSize: number;
22-
diagnosticModel: 'push' | 'pull';
23-
additionalExtensions: string[];
24-
vitePress: {
25-
supportMdFile: boolean;
26-
};
27-
petiteVue: {
28-
supportHtmlFile: boolean;
29-
};
3023
}> {
3124
return _config().get('server')!;
3225
},

extensions/vscode/src/features/doctor.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,20 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
231231
});
232232
}
233233

234-
// check outdated vue language plugins
235-
// check node_modules has more than one vue versions
236-
// check ESLint, Prettier...
234+
if (
235+
vscode.workspace.getConfiguration('vue').has('server.additionalExtensions')
236+
|| vscode.workspace.getConfiguration('vue').has('server.petiteVue.supportHtmlFile')
237+
|| vscode.workspace.getConfiguration('vue').has('server.vitePress.supportMdFile')
238+
) {
239+
problems.push({
240+
title: 'Deprecated configuration',
241+
message: [
242+
'`vue.server.additionalExtensions`, `vue.server.petiteVue.supportHtmlFile`, and `vue.server.vitePress.supportMdFile` are deprecated. Please remove them from your settings.',
243+
'',
244+
'- PR: https://github.com/vuejs/language-tools/pull/4321',
245+
].join('\n'),
246+
});
247+
}
237248

238249
return problems;
239250
}

extensions/vscode/src/features/nameCasing.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,7 @@ export async function activate(_context: vscode.ExtensionContext, client: BaseLa
136136
}
137137

138138
async function update(document: vscode.TextDocument | undefined) {
139-
if (
140-
document?.languageId === 'vue'
141-
|| (config.server.vitePress.supportMdFile && document?.languageId === 'markdown')
142-
|| (config.server.petiteVue.supportHtmlFile && document?.languageId === 'html')
143-
) {
139+
if (document && vscode.languages.match(selector, document)) {
144140
let detected: Awaited<ReturnType<typeof detect>> | undefined;
145141
let attrNameCasing = attrNameCasings.get(document.uri.toString());
146142
let tagNameCasing = tagNameCasings.get(document.uri.toString());

extensions/vscode/src/nodeClientMain.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function activate(context: vscode.ExtensionContext) {
3535
runOptions.execArgv.push("--max-old-space-size=" + config.server.maxOldSpaceSize);
3636
}
3737
const debugOptions: lsp.ForkOptions = { execArgv: ['--nolazy', '--inspect=' + port] };
38-
let serverOptions: lsp.ServerOptions = {
38+
const serverOptions: lsp.ServerOptions = {
3939
run: {
4040
module: serverModule.fsPath,
4141
transport: lsp.TransportKind.ipc,
@@ -55,7 +55,7 @@ export async function activate(context: vscode.ExtensionContext) {
5555
isTrusted: true,
5656
supportHtml: true,
5757
},
58-
outputChannel
58+
outputChannel,
5959
};
6060
const client = new _LanguageClient(
6161
id,
@@ -145,18 +145,17 @@ try {
145145
s => s + `.filter(p=>p.name!=='typescript-vue-plugin-bundle')`
146146
);
147147
}
148-
else if (!enabledHybridMode) {
148+
else if (enabledHybridMode) {
149149
// patch readPlugins
150150
text = text.replace(
151151
'languages:Array.isArray(e.languages)',
152152
[
153153
'languages:',
154-
`e.name==='typescript-vue-plugin-bundle'?[]:`,
155-
'Array.isArray(e.languages)',
154+
`e.name==='typescript-vue-plugin-bundle'?[${config.server.includeLanguages.map(lang => `"${lang}"`).join(',')}]`,
155+
':Array.isArray(e.languages)',
156156
].join(''),
157157
);
158-
}
159-
else {
158+
160159
// VSCode < 1.87.0
161160
text = text.replace('t.$u=[t.$r,t.$s,t.$p,t.$q]', s => s + '.concat("vue")'); // patch jsTsLanguageModes
162161
text = text.replace('.languages.match([t.$p,t.$q,t.$r,t.$s]', s => s + '.concat("vue")'); // patch isSupportedLanguageMode

packages/component-meta/lib/base.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ function createCheckerWorker(
9292
if (parsedCommandLine.vueOptions.extensions.some(ext => fileName.endsWith(ext))) {
9393
return 'vue';
9494
}
95+
if (parsedCommandLine.vueOptions.vitePressExtensions.some(ext => fileName.endsWith(ext))) {
96+
return 'markdown';
97+
}
98+
if (parsedCommandLine.vueOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
99+
return 'html';
100+
}
95101
return vue.resolveCommonLanguageId(fileName);
96102
},
97103
scriptIdToFileName: id => id,

0 commit comments

Comments
 (0)