Skip to content

Commit 53cd1e5

Browse files
committed
feat: update for mpx
1 parent 7515686 commit 53cd1e5

File tree

5 files changed

+14
-199
lines changed

5 files changed

+14
-199
lines changed

packages/language-core/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ export interface Sfc {
168168
| undefined
169169
scriptSetup:
170170
| (SfcBlock & {
171-
// https://github.com/vuejs/rfcs/discussions/436
172171
generic: SfcBlockAttr | undefined
173172
ast: ts.SourceFile
174173
})

vscode/languages/mpx-language-configuration.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@
109109
}
110110
}
111111
],
112-
// https://github.com/vuejs/language-tools/issues/1762
113112
"indentationRules": {
114-
// "increaseIndentPattern": "<(?!\\?|(?:area|base|br|col|frame|hr|html|img|input|keygen|link|menuitem|meta|param|source|track|wbr|script|style)\\b|[^>]*\\/>)([-_\\.A-Za-z0-9]+)(?=\\s|>)\\b[^>]*>(?!.*<\\/\\1>)|<!--(?!.*-->)|\\{[^}\"']*$",
115-
// add (?!\\s*\\() to fix https://github.com/vuejs/language-tools/issues/1847#issuecomment-1246101071
116113
"increaseIndentPattern": "<(?!\\?|(?:area|base|br|col|frame|hr|html|img|input|keygen|link|menuitem|meta|param|source|track|wbr|script|style)\\b|[^>]*\\/>)([-_\\.A-Za-z0-9]+)(?=\\s|>)\\b[^>]*>(?!\\s*\\()(?!.*<\\/\\1>)|<!--(?!.*-->)|\\{[^}\"']*$",
117114
"decreaseIndentPattern": "^\\s*(<\\/(?!html)[-_\\.A-Za-z0-9]+\\b[^>]*>|-->|\\})"
118115
}

vscode/src/client.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ export const { activate, deactivate } = defineExtension(async () => {
6464
})
6565

6666
const context = extensionContext.value!
67+
6768
activateLanguageClient(
6869
context,
6970
(id, name, documentSelector, initOptions, port, outputChannel) => {
7071
class _LanguageClient extends lsp.LanguageClient {
7172
fillInitializeParams(params: lsp.InitializeParams) {
72-
// fix https://github.com/vuejs/language-tools/issues/1959
7373
params.locale = vscode.env.language
7474
}
7575
}
@@ -163,6 +163,7 @@ try {
163163
paths: [tsExtension.extensionPath],
164164
})
165165

166+
// 劫持修改 ts 插件内置语言支持 mpx
166167
// @ts-expect-error ignore
167168
fs.readFileSync = (...args) => {
168169
if (args[0] === extensionJsPath) {
@@ -190,22 +191,7 @@ try {
190191
)
191192

192193
/**
193-
* VSCode < 1.87.0
194-
*/
195-
196-
// patch jsTsLanguageModes
197-
text = text.replace(
198-
't.$u=[t.$r,t.$s,t.$p,t.$q]',
199-
s => s + '.concat("mpx")',
200-
)
201-
// patch isSupportedLanguageMode
202-
text = text.replace(
203-
'.languages.match([t.$p,t.$q,t.$r,t.$s]',
204-
s => s + '.concat("mpx")',
205-
)
206-
207-
/**
208-
* VSCode >= 1.87.0
194+
* only support VSCode >= 1.87.0
209195
*/
210196

211197
// patch jsTsLanguageModes
@@ -225,7 +211,7 @@ try {
225211
return readFileSync(...args)
226212
}
227213

228-
// Hot Module Replacement
214+
// 热更重启 ts 插件
229215
const loadedModule = require.cache[extensionJsPath]
230216
if (loadedModule) {
231217
delete require.cache[extensionJsPath]

vscode/src/features/doctor.ts

Lines changed: 7 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ export async function activate(client: BaseLanguageClient) {
7272
}
7373

7474
content += '---\n\n'
75-
content += `> Have any questions about the report message? You can see how it is composed by inspecting the [source code](https://github.com/vuejs/language-tools/blob/master/extensions/vscode/src/features/doctor.ts).\n\n`
76-
7775
return content.trim()
7876
},
7977
}),
@@ -109,127 +107,22 @@ export async function activate(client: BaseLanguageClient) {
109107
}
110108

111109
async function getProblems(fileUri: vscode.Uri) {
112-
const vueDoc = vscode.workspace.textDocuments.find(
110+
const mpxDoc = vscode.workspace.textDocuments.find(
113111
doc => doc.fileName === fileUri.fsPath,
114112
)
115-
const sfc: SFCParseResult = vueDoc
113+
114+
const sfc: SFCParseResult = mpxDoc
116115
? await client.sendRequest(ExecuteCommandRequest.type, {
117116
command: commands.parseSfc,
118-
arguments: [vueDoc.getText()],
117+
arguments: [mpxDoc.getText()],
119118
} satisfies ExecuteCommandParams)
120119
: undefined
121-
const vueMod = getPackageJsonOfWorkspacePackage(fileUri.fsPath, 'mpx')
122-
const domMod = getPackageJsonOfWorkspacePackage(
123-
fileUri.fsPath,
124-
'@vue/runtime-dom',
125-
)
120+
126121
const problems: {
127122
title: string
128123
message: string
129124
}[] = []
130125

131-
if (vueMod && semver.lt(vueMod.json.version, '2.7.0') && !domMod) {
132-
// check vue version < 2.7 but @vue/runtime-dom missing
133-
problems.push({
134-
title: '`@vue/runtime-dom` missing for Vue 2',
135-
message: [
136-
"Vue 2 does not have JSX types definitions, so template type checking will not work correctly. You can resolve this problem by installing `@vue/runtime-dom` and adding it to your project's `devDependencies`.",
137-
'',
138-
'- vue: ' + vueMod.path,
139-
].join('\n'),
140-
})
141-
} else if (
142-
vueMod &&
143-
semver.gte(vueMod.json.version, '2.7.0') &&
144-
semver.lt(vueMod.json.version, '3.0.0') &&
145-
domMod
146-
) {
147-
// check vue version >= 2.7 and < 3 but installed @vue/runtime-dom
148-
problems.push({
149-
title: 'Unnecessary `@vue/runtime-dom`',
150-
message: [
151-
'Vue 2.7 already includes JSX type definitions. You can remove the `@vue/runtime-dom` dependency from package.json.',
152-
'',
153-
'- vue: ' + vueMod.path,
154-
'- @vue/runtime-dom: ' + domMod.path,
155-
].join('\n'),
156-
})
157-
}
158-
159-
// check @types/node > 18.8.0 && < 18.11.1
160-
const typesNodeMod = getPackageJsonOfWorkspacePackage(
161-
fileUri.fsPath,
162-
'@types/node',
163-
)
164-
if (
165-
typesNodeMod &&
166-
semver.gte(typesNodeMod.json.version, '18.8.1') &&
167-
semver.lte(typesNodeMod.json.version, '18.11.0')
168-
) {
169-
problems.push({
170-
title: 'Incompatible `@types/node` version',
171-
message: [
172-
"`@types/node`'s version `" +
173-
typesNodeMod.json.version +
174-
'` is incompatible with Vue. It will cause broken DOM event types in template.',
175-
'',
176-
'You can update `@types/node` to `18.11.1` or later to resolve.',
177-
'',
178-
'- @types/node: ' + typesNodeMod.path,
179-
'- Issue: https://github.com/vuejs/language-tools/issues/1985',
180-
].join('\n'),
181-
})
182-
}
183-
184-
const pugPluginPkg = await getPackageJsonOfWorkspacePackage(
185-
fileUri.fsPath,
186-
'@vue/language-plugin-pug',
187-
)
188-
189-
// check using pug but don't install @vue/language-plugin-pug
190-
if (sfc?.descriptor.template?.lang === 'pug' && !pugPluginPkg) {
191-
problems.push({
192-
title: '`@vue/language-plugin-pug` missing',
193-
message: [
194-
'For `<template lang="pug">`, the `@vue/language-plugin-pug` plugin is required. Install it using `$ npm install -D @vue/language-plugin-pug` and add it to `vueCompilerOptions.plugins` to support TypeScript intellisense in Pug templates.',
195-
'',
196-
'- package.json',
197-
'```json',
198-
JSON.stringify(
199-
{ devDependencies: { '@vue/language-plugin-pug': 'latest' } },
200-
undefined,
201-
2,
202-
),
203-
'```',
204-
'',
205-
'- tsconfig.json / jsconfig.json',
206-
'```jsonc',
207-
JSON.stringify(
208-
{ vueCompilerOptions: { plugins: ['@vue/language-plugin-pug'] } },
209-
undefined,
210-
2,
211-
),
212-
'```',
213-
].join('\n'),
214-
})
215-
}
216-
217-
// check using pug but outdated @vue/language-plugin-pug
218-
if (
219-
sfc?.descriptor.template?.lang === 'pug' &&
220-
pugPluginPkg &&
221-
!semver.gte(pugPluginPkg.json.version, '2.0.5')
222-
) {
223-
problems.push({
224-
title: 'Outdated `@vue/language-plugin-pug`',
225-
message: [
226-
'The version of `@vue/language-plugin-pug` is too low, it is required to upgrade to `2.0.5` or later.',
227-
'',
228-
'- @vue/language-plugin-pug: ' + pugPluginPkg.path,
229-
].join('\n'),
230-
})
231-
}
232-
233126
// check syntax highlight extension installed
234127
if (sfc) {
235128
const blocks = [
@@ -266,75 +159,15 @@ export async function activate(client: BaseLanguageClient) {
266159
}
267160
}
268161

269-
// emmet.includeLanguages
270-
const emmetIncludeLanguages = vscode.workspace
271-
.getConfiguration('emmet')
272-
.get<{ [lang: string]: string }>('includeLanguages')
273-
if (emmetIncludeLanguages?.['mpx']) {
274-
problems.push({
275-
title: 'Unnecessary `emmet.includeLanguages.mpx`',
276-
message:
277-
'Vue language server already supports Emmet. You can remove `emmet.includeLanguages.mpx` from `.vscode/settings.json`.',
278-
})
279-
}
280-
281-
// files.associations
282-
const filesAssociations = vscode.workspace
283-
.getConfiguration('files')
284-
.get<{ [pattern: string]: string }>('associations')
285-
if (filesAssociations?.['*.mpx'] === 'html') {
286-
problems.push({
287-
title: 'Unnecessary `files.associations["*.mpx"]`',
288-
message:
289-
'With `"files.associations": { "*.mpx": html }`, language server cannot to recognize Vue files. You can remove `files.associations["*.mpx"]` from `.vscode/settings.json`.',
290-
})
291-
}
292-
293-
// check tsdk version should be higher than 5.0.0
162+
// check tsdk > 5.0.0
294163
const tsdk = (await getTsdk(extensionContext.value!))!
295164
if (tsdk.version && !semver.gte(tsdk.version, '5.0.0')) {
296165
problems.push({
297166
title: 'Requires TSDK 5.0 or higher',
298-
message: [
299-
`Extension >= 2.0 requires TSDK 5.0+. You are currently using TSDK ${tsdk.version}, please upgrade to TSDK.`,
300-
'If you need to use TSDK 4.x, please downgrade the extension to v1.',
301-
].join('\n'),
302-
})
303-
}
304-
305-
if (
306-
vscode.workspace
307-
.getConfiguration('mpx')
308-
.has('server.additionalExtensions') ||
309-
vscode.workspace
310-
.getConfiguration('mpx')
311-
.has('server.petiteVue.supportHtmlFile') ||
312-
vscode.workspace
313-
.getConfiguration('mpx')
314-
.has('server.vitePress.supportMdFile')
315-
) {
316-
problems.push({
317-
title: 'Deprecated configuration',
318-
message: [
319-
'`mpx.server.additionalExtensions`, `mpx.server.petiteVue.supportHtmlFile`, and `mpx.server.vitePress.supportMdFile` are deprecated. Please remove them from your settings.',
320-
'',
321-
'- PR: https://github.com/vuejs/language-tools/pull/4321',
322-
].join('\n'),
167+
message: `Extension >= 2.0 requires TSDK 5.0+. You are currently using TSDK ${tsdk.version}, please upgrade to TSDK.`,
323168
})
324169
}
325170

326171
return problems
327172
}
328173
}
329-
330-
function getPackageJsonOfWorkspacePackage(folder: string, pkg: string) {
331-
try {
332-
const path = require.resolve(pkg + '/package.json', { paths: [folder] })
333-
return {
334-
path,
335-
json: require(path) as { version: string },
336-
}
337-
} catch {
338-
// noop
339-
}
340-
}

vscode/src/languageClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ async function activateLc(
6767
createLc: CreateLanguageClient,
6868
) {
6969
useVscodeContext('mpx.activated', true)
70-
const outputChannel = useOutputChannel('Vue Language Server')
70+
const outputChannel = useOutputChannel('Mpx Language Server')
7171
const selectors = config.server.includeLanguages
7272

7373
client = createLc(
74-
'mpx',
75-
'Mpx',
74+
'mpx-language-server',
75+
'Mpx Language Server',
7676
selectors,
7777
await getInitializationOptions(context),
7878
6009,

0 commit comments

Comments
 (0)