From ce61a0d189e1ad35e087fa5cdc7ff06dc1eda59b Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Wed, 10 Jul 2024 17:19:20 +0800 Subject: [PATCH] fix(language-core): preserve backward compatibility --- packages/component-meta/lib/base.ts | 2 +- packages/language-core/lib/languagePlugin.ts | 18 ++++++++++++++++++ packages/language-server/lib/initialize.ts | 4 ++-- packages/language-server/node.ts | 4 ++-- .../tests/utils/createTester.ts | 4 ++-- .../language-service/tests/utils/format.ts | 4 ++-- packages/tsc/index.ts | 2 +- packages/tsc/tests/dts.spec.ts | 2 +- packages/typescript-plugin/index.ts | 2 +- 9 files changed, 30 insertions(+), 12 deletions(-) diff --git a/packages/component-meta/lib/base.ts b/packages/component-meta/lib/base.ts index d2e7302560..2b18d45d16 100644 --- a/packages/component-meta/lib/base.ts +++ b/packages/component-meta/lib/base.ts @@ -144,7 +144,7 @@ export function baseCreate( } }; - const vueLanguagePlugin = vue.createVueLanguagePlugin( + const vueLanguagePlugin = vue.createVueLanguagePlugin2( ts, id => id, vue.createRootFileChecker( diff --git a/packages/language-core/lib/languagePlugin.ts b/packages/language-core/lib/languagePlugin.ts index 2f86d6f558..13d2d9c86f 100644 --- a/packages/language-core/lib/languagePlugin.ts +++ b/packages/language-core/lib/languagePlugin.ts @@ -69,7 +69,25 @@ export function createRootFileChecker( }; } +// TODO: replace `createVueLanguagePlugin` with `createVueLanguagePlugin2` in 2.1 export function createVueLanguagePlugin( + ts: typeof import('typescript'), + asFileName: (scriptId: T) => string, + _getProjectVersion: (() => string) | undefined, + isRootFile: (fileName: string) => boolean, + compilerOptions: ts.CompilerOptions, + vueCompilerOptions: VueCompilerOptions +): LanguagePlugin { + return createVueLanguagePlugin2( + ts, + asFileName, + isRootFile, + compilerOptions, + vueCompilerOptions, + ); +} + +export function createVueLanguagePlugin2( ts: typeof import('typescript'), asFileName: (scriptId: T) => string, isRootFile: (fileName: string) => boolean, diff --git a/packages/language-server/lib/initialize.ts b/packages/language-server/lib/initialize.ts index d4f804d339..042e6d13f5 100644 --- a/packages/language-server/lib/initialize.ts +++ b/packages/language-server/lib/initialize.ts @@ -1,6 +1,6 @@ import type { LanguageServer } from '@volar/language-server'; import { createTypeScriptProject } from '@volar/language-server/node'; -import { createParsedCommandLine, createRootFileChecker, createVueLanguagePlugin, getAllExtensions, resolveVueCompilerOptions, VueCompilerOptions } from '@vue/language-core'; +import { createParsedCommandLine, createRootFileChecker, createVueLanguagePlugin2, getAllExtensions, resolveVueCompilerOptions, VueCompilerOptions } from '@vue/language-core'; import { Disposable, getFullLanguageServicePlugins, InitializeParams } from '@vue/language-service'; import type * as ts from 'typescript'; @@ -39,7 +39,7 @@ export function initialize( } updateFileWatcher(vueCompilerOptions); return { - languagePlugins: [createVueLanguagePlugin( + languagePlugins: [createVueLanguagePlugin2( ts, s => uriConverter.asFileName(s), createRootFileChecker( diff --git a/packages/language-server/node.ts b/packages/language-server/node.ts index c1c6652f62..850a5dec91 100644 --- a/packages/language-server/node.ts +++ b/packages/language-server/node.ts @@ -1,5 +1,5 @@ import { createConnection, createServer, loadTsdkByPath } from '@volar/language-server/node'; -import { createParsedCommandLine, createVueLanguagePlugin, resolveVueCompilerOptions } from '@vue/language-core'; +import { createParsedCommandLine, createVueLanguagePlugin2, resolveVueCompilerOptions } from '@vue/language-core'; import { getHybridModeLanguageServicePlugins } from '@vue/language-service'; import * as namedPipeClient from '@vue/typescript-plugin/lib/client'; import { createHybridModeProject } from './lib/hybridModeProject'; @@ -27,7 +27,7 @@ connection.onInitialize(params => { options: ts.getDefaultCompilerOptions(), }; return { - languagePlugins: [createVueLanguagePlugin( + languagePlugins: [createVueLanguagePlugin2( ts, asFileName, () => false, diff --git a/packages/language-service/tests/utils/createTester.ts b/packages/language-service/tests/utils/createTester.ts index d79c3a5614..10f6c7d77d 100644 --- a/packages/language-service/tests/utils/createTester.ts +++ b/packages/language-service/tests/utils/createTester.ts @@ -3,7 +3,7 @@ import { TypeScriptProjectHost, createLanguageServiceHost, resolveFileLanguageId import * as path from 'path'; import * as ts from 'typescript'; import { URI } from 'vscode-uri'; -import { createParsedCommandLine, createRootFileChecker, createVueLanguagePlugin, getFullLanguageServicePlugins } from '../..'; +import { createParsedCommandLine, createRootFileChecker, createVueLanguagePlugin2, getFullLanguageServicePlugins } from '../..'; import { createMockServiceEnv, fileNameToUri, uriToFileName } from './mockEnv'; export const rootUri = URI.file(path.resolve(__dirname, '../../../../test-workspace/language-service')); @@ -24,7 +24,7 @@ function createTester(rootUri: URI) { getCompilationSettings: () => parsedCommandLine.options, getScriptSnapshot, }; - const vueLanguagePlugin = createVueLanguagePlugin( + const vueLanguagePlugin = createVueLanguagePlugin2( ts, uriToFileName, createRootFileChecker( diff --git a/packages/language-service/tests/utils/format.ts b/packages/language-service/tests/utils/format.ts index 1f236f21fa..05dfb55c58 100644 --- a/packages/language-service/tests/utils/format.ts +++ b/packages/language-service/tests/utils/format.ts @@ -2,10 +2,10 @@ import * as kit from '@volar/kit'; import * as ts from 'typescript'; import { describe, expect, it } from 'vitest'; import type { URI } from 'vscode-uri'; -import { createVueLanguagePlugin, getFullLanguageServicePlugins, resolveVueCompilerOptions } from '../..'; +import { createVueLanguagePlugin2, getFullLanguageServicePlugins, resolveVueCompilerOptions } from '../..'; const resolvedVueOptions = resolveVueCompilerOptions({}); -const vueLanguagePlugin = createVueLanguagePlugin( +const vueLanguagePlugin = createVueLanguagePlugin2( ts, () => '', () => false, diff --git a/packages/tsc/index.ts b/packages/tsc/index.ts index 5189f0715e..48c9ca8408 100644 --- a/packages/tsc/index.ts +++ b/packages/tsc/index.ts @@ -25,7 +25,7 @@ export function run() { options.host!.writeFile = (fileName, contents, ...args) => { return writeFile(fileName, removeEmitGlobalTypes(contents), ...args); }; - const vueLanguagePlugin = vue.createVueLanguagePlugin( + const vueLanguagePlugin = vue.createVueLanguagePlugin2( ts, id => id, vue.createRootFileChecker( diff --git a/packages/tsc/tests/dts.spec.ts b/packages/tsc/tests/dts.spec.ts index d0ac81b6fc..c3a2bc21e1 100644 --- a/packages/tsc/tests/dts.spec.ts +++ b/packages/tsc/tests/dts.spec.ts @@ -31,7 +31,7 @@ describe('vue-tsc-dts', () => { vueOptions = typeof configFilePath === 'string' ? vue.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions : vue.resolveVueCompilerOptions({ extensions: ['.vue', '.cext'] }); - const vueLanguagePlugin = vue.createVueLanguagePlugin( + const vueLanguagePlugin = vue.createVueLanguagePlugin2( ts, id => id, vue.createRootFileChecker( diff --git a/packages/typescript-plugin/index.ts b/packages/typescript-plugin/index.ts index 37abdb3dd1..9545d8f3c5 100644 --- a/packages/typescript-plugin/index.ts +++ b/packages/typescript-plugin/index.ts @@ -8,7 +8,7 @@ const windowsPathReg = /\\/g; const plugin = createLanguageServicePlugin( (ts, info) => { const vueOptions = getVueCompilerOptions(); - const languagePlugin = vue.createVueLanguagePlugin( + const languagePlugin = vue.createVueLanguagePlugin2( ts, id => id, info.project.projectKind === ts.server.ProjectKind.Inferred