Skip to content

Commit

Permalink
fix(language-core): preserve backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jul 10, 2024
1 parent 699d2dc commit ce61a0d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/component-meta/lib/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function baseCreate(
}
};

const vueLanguagePlugin = vue.createVueLanguagePlugin<string>(
const vueLanguagePlugin = vue.createVueLanguagePlugin2<string>(
ts,
id => id,
vue.createRootFileChecker(
Expand Down
18 changes: 18 additions & 0 deletions packages/language-core/lib/languagePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,25 @@ export function createRootFileChecker(
};
}

// TODO: replace `createVueLanguagePlugin` with `createVueLanguagePlugin2` in 2.1
export function createVueLanguagePlugin<T>(
ts: typeof import('typescript'),
asFileName: (scriptId: T) => string,
_getProjectVersion: (() => string) | undefined,
isRootFile: (fileName: string) => boolean,
compilerOptions: ts.CompilerOptions,
vueCompilerOptions: VueCompilerOptions
): LanguagePlugin<T, VueVirtualCode> {
return createVueLanguagePlugin2(
ts,
asFileName,
isRootFile,
compilerOptions,
vueCompilerOptions,
);
}

export function createVueLanguagePlugin2<T>(
ts: typeof import('typescript'),
asFileName: (scriptId: T) => string,
isRootFile: (fileName: string) => boolean,
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/lib/initialize.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -39,7 +39,7 @@ export function initialize(
}
updateFileWatcher(vueCompilerOptions);
return {
languagePlugins: [createVueLanguagePlugin(
languagePlugins: [createVueLanguagePlugin2(
ts,
s => uriConverter.asFileName(s),
createRootFileChecker(
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/node.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -27,7 +27,7 @@ connection.onInitialize(params => {
options: ts.getDefaultCompilerOptions(),
};
return {
languagePlugins: [createVueLanguagePlugin(
languagePlugins: [createVueLanguagePlugin2(
ts,
asFileName,
() => false,
Expand Down
4 changes: 2 additions & 2 deletions packages/language-service/tests/utils/createTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -24,7 +24,7 @@ function createTester(rootUri: URI) {
getCompilationSettings: () => parsedCommandLine.options,
getScriptSnapshot,
};
const vueLanguagePlugin = createVueLanguagePlugin(
const vueLanguagePlugin = createVueLanguagePlugin2(
ts,
uriToFileName,
createRootFileChecker(
Expand Down
4 changes: 2 additions & 2 deletions packages/language-service/tests/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<URI>(
const vueLanguagePlugin = createVueLanguagePlugin2<URI>(
ts,
() => '',
() => false,
Expand Down
2 changes: 1 addition & 1 deletion packages/tsc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function run() {
options.host!.writeFile = (fileName, contents, ...args) => {
return writeFile(fileName, removeEmitGlobalTypes(contents), ...args);
};
const vueLanguagePlugin = vue.createVueLanguagePlugin<string>(
const vueLanguagePlugin = vue.createVueLanguagePlugin2<string>(
ts,
id => id,
vue.createRootFileChecker(
Expand Down
2 changes: 1 addition & 1 deletion packages/tsc/tests/dts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(
const vueLanguagePlugin = vue.createVueLanguagePlugin2<string>(
ts,
id => id,
vue.createRootFileChecker(
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const windowsPathReg = /\\/g;
const plugin = createLanguageServicePlugin(
(ts, info) => {
const vueOptions = getVueCompilerOptions();
const languagePlugin = vue.createVueLanguagePlugin<string>(
const languagePlugin = vue.createVueLanguagePlugin2<string>(
ts,
id => id,
info.project.projectKind === ts.server.ProjectKind.Inferred
Expand Down

0 comments on commit ce61a0d

Please sign in to comment.