Skip to content

Commit

Permalink
feat: upgrade to volar 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jan 22, 2024
1 parent 66d6fff commit f3de428
Show file tree
Hide file tree
Showing 24 changed files with 160 additions and 168 deletions.
2 changes: 1 addition & 1 deletion extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@
"devDependencies": {
"@types/semver": "^7.5.3",
"@types/vscode": "^1.82.0",
"@volar/vscode": "2.0.0-alpha.14",
"@volar/vscode": "~2.0.0",
"@vue/language-core": "1.8.27",
"@vue/language-server": "1.8.27",
"esbuild": "latest",
Expand Down
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
"devDependencies": {
"@lerna-lite/cli": "latest",
"@lerna-lite/publish": "latest",
"@volar/language-service": "2.0.0-alpha.14",
"@volar/language-service": "~2.0.0",
"typescript": "latest",
"vite": "latest",
"vitest": "latest"
},
"pnpm": {
"overrides": {
"@volar/language-service": "2.0.0-alpha.14"
}
}
}
2 changes: 1 addition & 1 deletion packages/component-meta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"directory": "packages/component-meta"
},
"dependencies": {
"@volar/typescript": "2.0.0-alpha.14",
"@volar/typescript": "~2.0.0",
"@vue/language-core": "1.8.27",
"path-browserify": "^1.0.1",
"vue-component-type-helpers": "1.8.27"
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"directory": "packages/language-core"
},
"dependencies": {
"@volar/language-core": "2.0.0-alpha.14",
"@volar/language-core": "~2.0.0",
"@vue/compiler-dom": "^3.4.0",
"@vue/shared": "^3.4.0",
"computeds": "^0.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/language-plugin-pug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@vue/language-core": "1.8.27"
},
"dependencies": {
"@volar/source-map": "2.0.0-alpha.14",
"volar-service-pug": "0.0.26"
"@volar/source-map": "~2.0.0",
"volar-service-pug": "volar-2.0"
}
}
4 changes: 2 additions & 2 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"directory": "packages/language-server"
},
"dependencies": {
"@volar/language-core": "2.0.0-alpha.14",
"@volar/language-server": "2.0.0-alpha.14",
"@volar/language-core": "~2.0.0",
"@volar/language-server": "~2.0.0",
"@vue/language-core": "1.8.27",
"@vue/language-service": "1.8.27",
"vscode-languageserver-protocol": "^3.17.5",
Expand Down
10 changes: 5 additions & 5 deletions packages/language-server/src/nodeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ connection.onInitialize(params => {
const ts = getTsLib();
const [commandLine, vueOptions] = await parseCommandLine();
const resolvedVueOptions = vue.resolveVueCompilerOptions(vueOptions);
const languages = vue.resolveLanguages({}, ts, serviceEnv.typescript.uriToFileName, commandLine?.options ?? {}, resolvedVueOptions, options.codegenStack);
const languages = vue.resolveLanguages({}, ts, serviceEnv.typescript!.uriToFileName, commandLine?.options ?? {}, resolvedVueOptions, options.codegenStack);

envToVueOptions.set(serviceEnv, resolvedVueOptions);

Expand Down Expand Up @@ -129,15 +129,15 @@ connection.onRequest(GetComponentMeta.type, async params => {
if (!checker) {
checker = componentMeta.baseCreate(
getTsLib(),
langaugeService.context.typescript!.configFileName,
langaugeService.context.typescript!.projectHost,
langaugeService.context.language.typescript!.configFileName,
langaugeService.context.language.typescript!.projectHost,
envToVueOptions.get(langaugeService.context.env)!,
{},
langaugeService.context.typescript!.languageServiceHost.getCurrentDirectory() + '/tsconfig.json.global.vue',
langaugeService.context.language.typescript!.languageServiceHost.getCurrentDirectory() + '/tsconfig.json.global.vue',
);
checkers.set(project, checker);
}
return checker?.getComponentMeta(langaugeService.context.env.typescript.uriToFileName(params.uri));
return checker?.getComponentMeta(langaugeService.context.env.typescript!.uriToFileName(params.uri));
});

function getTsLib() {
Expand Down
24 changes: 12 additions & 12 deletions packages/language-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@
"update-html-data": "node ./scripts/update-html-data.js"
},
"dependencies": {
"@volar/language-core": "2.0.0-alpha.14",
"@volar/language-service": "2.0.0-alpha.14",
"@volar/typescript": "2.0.0-alpha.14",
"@volar/language-core": "~2.0.0",
"@volar/language-service": "~2.0.0",
"@volar/typescript": "~2.0.0",
"@vue/compiler-dom": "^3.4.0",
"@vue/language-core": "1.8.27",
"@vue/shared": "^3.4.0",
"computeds": "^0.0.1",
"path-browserify": "^1.0.1",
"volar-service-css": "0.0.26",
"volar-service-emmet": "0.0.26",
"volar-service-html": "0.0.26",
"volar-service-json": "0.0.26",
"volar-service-pug": "0.0.26",
"volar-service-pug-beautify": "0.0.26",
"volar-service-typescript": "0.0.26",
"volar-service-typescript-twoslash-queries": "0.0.26",
"volar-service-css": "volar-2.0",
"volar-service-emmet": "volar-2.0",
"volar-service-html": "volar-2.0",
"volar-service-json": "volar-2.0",
"volar-service-pug": "volar-2.0",
"volar-service-pug-beautify": "volar-2.0",
"volar-service-typescript": "volar-2.0",
"volar-service-typescript-twoslash-queries": "volar-2.0",
"vscode-html-languageservice": "^5.1.0",
"vscode-languageserver-textdocument": "^1.0.11"
},
"devDependencies": {
"@types/node": "latest",
"@types/path-browserify": "latest",
"@volar/kit": "2.0.0-alpha.14",
"@volar/kit": "~2.0.0",
"vscode-languageserver-protocol": "^3.17.5",
"vscode-uri": "^3.0.8"
}
Expand Down
8 changes: 4 additions & 4 deletions packages/language-service/src/ideFeatures/nameCasing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function convertTagName(
vueCompilerOptions: VueCompilerOptions,
) {

const sourceFile = context.files.get(uri);
const sourceFile = context.language.files.get(uri);
if (!sourceFile)
return;

Expand Down Expand Up @@ -65,7 +65,7 @@ export async function convertAttrName(
vueCompilerOptions: VueCompilerOptions,
) {

const sourceFile = context.files.get(uri);
const sourceFile = context.language.files.get(uri);
if (!sourceFile)
return;

Expand Down Expand Up @@ -141,8 +141,8 @@ export function detect(
attr: AttrNameCasing[],
} {

const rootFile = context.files.get(uri)?.generated?.code;
if (!(rootFile instanceof VueGeneratedCode) || !context.typescript) {
const rootFile = context.language.files.get(uri)?.generated?.code;
if (!(rootFile instanceof VueGeneratedCode) || !context.language.typescript) {
return {
tag: [],
attr: [],
Expand Down
4 changes: 2 additions & 2 deletions packages/language-service/src/languageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function resolveServices(

for (const map of context.documents.getMaps(virtualCode)) {

const sourceVirtualFile = context.files.get(map.sourceFileDocument.uri)?.generated?.code;
const sourceVirtualFile = context.language.files.get(map.sourceFileDocument.uri)?.generated?.code;

if (sourceVirtualFile instanceof VueGeneratedCode) {

Expand Down Expand Up @@ -177,7 +177,7 @@ export function resolveServices(
const componentName = newName ?? item.textEdit.newText;
const optionEdit = createAddComponentToOptionEdit(ts, ast, componentName);
if (optionEdit) {
const textDoc = context.documents.get(context.documents.getVirtualCodeUri(context.files.getByVirtualCode(virtualCode).id, virtualCode.id), virtualCode.languageId, virtualCode.snapshot);
const textDoc = context.documents.get(context.documents.getVirtualCodeUri(context.language.files.getByVirtualCode(virtualCode).id, virtualCode.id), virtualCode.languageId, virtualCode.snapshot);
item.additionalTextEdits.push({
range: {
start: textDoc.positionAt(optionEdit.range.start),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function create(ts: typeof import('typescript/lib/tsserverlibrary')): Ser
if (!program)
return;

const sourceFile = program.getSourceFile(context.env.typescript.uriToFileName(document.uri));
const sourceFile = program.getSourceFile(context.env.typescript!.uriToFileName(document.uri));
if (!sourceFile)
return;

Expand All @@ -39,7 +39,7 @@ export function create(ts: typeof import('typescript/lib/tsserverlibrary')): Ser

const token = context.inject<Provide, 'typescript/languageServiceHost'>('typescript/languageServiceHost').getCancellationToken?.();
if (token) {
context.inject<Provide, 'typescript/languageService'>('typescript/languageService').getQuickInfoAtPosition(context.env.typescript.uriToFileName(document.uri), node.end);
context.inject<Provide, 'typescript/languageService'>('typescript/languageService').getQuickInfoAtPosition(context.env.typescript!.uriToFileName(document.uri), node.end);
if (token?.isCancellationRequested()) {
return; // check cancel here because type checker do not use cancel token
}
Expand Down
10 changes: 5 additions & 5 deletions packages/language-service/src/plugins/vue-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function create(

if (virtualCode) {
for (const map of context.documents.getMaps(virtualCode)) {
const sourceVirtualFile = context.files.get(map.sourceFileDocument.uri)?.generated?.code;
const sourceVirtualFile = context.language.files.get(map.sourceFileDocument.uri)?.generated?.code;
if (sourceVirtualFile instanceof VueGeneratedCode) {
await provideHtmlData(map, sourceVirtualFile);
}
Expand All @@ -93,7 +93,7 @@ export function create(

if (virtualCode) {
for (const map of context.documents.getMaps(virtualCode)) {
const sourceVirtualFile = context.files.get(map.sourceFileDocument.uri)?.generated?.code;
const sourceVirtualFile = context.language.files.get(map.sourceFileDocument.uri)?.generated?.code;
if (sourceVirtualFile instanceof VueGeneratedCode) {
afterHtmlCompletion(htmlComplete, map, sourceVirtualFile);
}
Expand All @@ -120,7 +120,7 @@ export function create(

for (const map of context.documents.getMaps(virtualCode)) {

const sourceVirtualFile = context.files.get(map.sourceFileDocument.uri)?.generated?.code;
const sourceVirtualFile = context.language.files.get(map.sourceFileDocument.uri)?.generated?.code;
const scanner = options.getScanner(baseServiceInstance, document);

if (sourceVirtualFile instanceof VueGeneratedCode && scanner) {
Expand Down Expand Up @@ -244,7 +244,7 @@ export function create(

for (const map of context.documents.getMaps(virtualCode)) {

const sourceVirtualFile = context.files.get(map.sourceFileDocument.uri)?.generated?.code;
const sourceVirtualFile = context.language.files.get(map.sourceFileDocument.uri)?.generated?.code;
if (!(sourceVirtualFile instanceof VueGeneratedCode))
continue;

Expand Down Expand Up @@ -306,7 +306,7 @@ export function create(

for (const map of context.documents.getMaps(virtualCode)) {

const sourceFile = context.files.get(map.sourceFileDocument.uri)?.generated?.code;
const sourceFile = context.language.files.get(map.sourceFileDocument.uri)?.generated?.code;
if (!(sourceFile instanceof VueGeneratedCode))
continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function create(ts: typeof import('typescript/lib/tsserverlibrary')): Ser
for (const [pointerPosition, hoverOffset] of hoverOffsets) {
for (const [tsOffset, mapping] of map.map.getGeneratedOffsets(hoverOffset)) {
if (vue.isHoverEnabled(mapping.data)) {
const fileName = context.env.typescript.uriToFileName(vueFile.id);
const fileName = context.env.typescript!.uriToFileName(vueFile.id);
const quickInfo = languageService.getQuickInfoAtPosition(fileName, tsOffset);
if (quickInfo) {
inlayHints.push({
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/tests/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ for (const dirName of testDirs) {
for (const file in inputFiles) {

const filePath = path.join(dir, 'input', file);
const uri = tester.serviceEnv.typescript.fileNameToUri(filePath);
const uri = tester.serviceEnv.typescript!.fileNameToUri(filePath);
const fileText = inputFiles[file];
const document = TextDocument.create('', '', 0, fileText);
const actions = findCompleteActions(fileText);
Expand Down
4 changes: 2 additions & 2 deletions packages/language-service/tests/findDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ for (const dirName of testDirs) {
for (const file in inputFiles) {

const filePath = path.join(dir, file);
const uri = tester.serviceEnv.typescript.fileNameToUri(filePath);
const uri = tester.serviceEnv.typescript!.fileNameToUri(filePath);
const fileText = inputFiles[file];
const document = TextDocument.create('', '', 0, fileText);
const actions = findActions(fileText);
Expand All @@ -41,7 +41,7 @@ for (const dirName of testDirs) {
expect(locations).toBeDefined();

const location = locations?.find(loc =>
loc.targetUri === tester.serviceEnv.typescript.fileNameToUri(targetFile)
loc.targetUri === tester.serviceEnv.typescript!.fileNameToUri(targetFile)
&& targetDocument.offsetAt(loc.targetSelectionRange.start) === action.targeRange.start
&& targetDocument.offsetAt(loc.targetSelectionRange.end) === action.targeRange.end
);
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/tests/inlayHint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for (const dirName of testDirs) {
for (const file in inputFiles) {

const filePath = path.join(dir, file);
const uri = tester.serviceEnv.typescript.fileNameToUri(filePath);
const uri = tester.serviceEnv.typescript!.fileNameToUri(filePath);
const fileText = inputFiles[file];
const document = TextDocument.create('', '', 0, fileText);
const actions = findActions(fileText);
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/tests/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ for (const dirName of testDirs) {
for (const file in inputFiles) {

const filePath = path.join(dir, file);
const uri = tester.serviceEnv.typescript.fileNameToUri(filePath);
const uri = tester.serviceEnv.typescript!.fileNameToUri(filePath);
const fileText = inputFiles[file];
const document = TextDocument.create('', '', 0, fileText);
const actions = findActions(fileText);
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/tests/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for (const dirName of testDirs) {
for (const file in inputFiles) {

const filePath = path.join(dir, 'input', file);
const uri = tester.serviceEnv.typescript.fileNameToUri(filePath);
const uri = tester.serviceEnv.typescript!.fileNameToUri(filePath);
const fileText = inputFiles[file];
const document = TextDocument.create('', '', 0, fileText);
const actions = findRenameActions(fileText);
Expand Down
12 changes: 6 additions & 6 deletions packages/language-service/tests/utils/createTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { URI } from 'vscode-uri';
import { createParsedCommandLine, resolveLanguages, resolveServices, resolveVueCompilerOptions } from '../../out';
import { createMockServiceEnv } from './mockEnv';

export const rootUri = URI.file(path.resolve(__dirname, '../../../../test-workspace/language-service'));
export const rootUri = URI.file(path.resolve(__dirname, '../../../../test-workspace/language-service')).toString();
export const tester = createTester(rootUri);

function createTester(rootUri: URI) {
function createTester(rootUri: string) {

const ts = require('typescript') as typeof import('typescript/lib/tsserverlibrary');
const serviceEnv = createMockServiceEnv(rootUri, () => currentVSCodeSettings ?? defaultVSCodeSettings);
const rootPath = serviceEnv.typescript.uriToFileName(rootUri.toString());
const rootPath = serviceEnv.typescript!.uriToFileName(rootUri.toString());
const realTsConfig = path.join(rootPath, 'tsconfig.json').replace(/\\/g, '/');
const parsedCommandLine = createParsedCommandLine(ts, ts.sys, realTsConfig);
parsedCommandLine.fileNames = parsedCommandLine.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
Expand All @@ -27,7 +27,7 @@ function createTester(rootUri: URI) {
getLanguageId: resolveCommonLanguageId,
};
const resolvedVueOptions = resolveVueCompilerOptions(parsedCommandLine.vueOptions);
const languages = resolveLanguages({}, ts, serviceEnv.typescript.uriToFileName, parsedCommandLine.options, resolvedVueOptions);
const languages = resolveLanguages({}, ts, serviceEnv.typescript!.uriToFileName, parsedCommandLine.options, resolvedVueOptions);
const services = resolveServices({}, ts, () => resolvedVueOptions);
const defaultVSCodeSettings: any = {
'typescript.preferences.quoteStyle': 'single',
Expand All @@ -44,8 +44,8 @@ function createTester(rootUri: URI) {
realTsConfig,
projectHost,
{
fileIdToFileName: serviceEnv.typescript.uriToFileName,
fileNameToFileId: serviceEnv.typescript.fileNameToUri,
fileIdToFileName: serviceEnv.typescript!.uriToFileName,
fileNameToFileId: serviceEnv.typescript!.fileNameToUri,
},
);
const languageService = createLanguageService(language, Object.values(services), serviceEnv);
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/tests/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest';
import { resolveLanguages, resolveServices, resolveVueCompilerOptions } from '../../out';

const resolvedVueOptions = resolveVueCompilerOptions({});
const languages = resolveLanguages({}, ts, fileId => formatter.env.typescript.uriToFileName(fileId), {}, resolvedVueOptions);
const languages = resolveLanguages({}, ts, fileId => formatter.env.typescript!.uriToFileName(fileId), {}, resolvedVueOptions);
const services = resolveServices({}, ts, () => resolvedVueOptions);
const formatter = kit.createFormatter(Object.values(languages), Object.values(services));

Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/tests/utils/mockEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const uriToFileName = (uri: string) => URI.parse(uri).fsPath.replace(/\\/g, '/')
const fileNameToUri = (fileName: string) => URI.file(fileName).toString();

export function createMockServiceEnv(
rootUri: URI,
rootUri: string,
getSettings = () => ({} as any)
): ServiceEnvironment {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/tsc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"vue-tsc": "./bin/vue-tsc.js"
},
"dependencies": {
"@volar/typescript": "2.0.0-alpha.14",
"@volar/typescript": "~2.0.0",
"@vue/language-core": "1.8.27",
"semver": "^7.5.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"directory": "packages/typescript-plugin"
},
"dependencies": {
"@volar/typescript": "2.0.0-alpha.14",
"@volar/typescript": "~2.0.0",
"@vue/language-core": "1.8.27"
}
}
Loading

0 comments on commit f3de428

Please sign in to comment.