Skip to content

Commit

Permalink
feat: upgrade volar to 2.2.0-alpha.12
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Apr 30, 2024
1 parent 7072a2a commit 31c9148
Show file tree
Hide file tree
Showing 22 changed files with 575 additions and 580 deletions.
2 changes: 1 addition & 1 deletion extensions/vscode/package.json
Expand Up @@ -515,7 +515,7 @@
"devDependencies": {
"@types/semver": "^7.5.3",
"@types/vscode": "^1.82.0",
"@volar/vscode": "2.2.0-alpha.10",
"@volar/vscode": "2.2.0-alpha.12",
"@vue/language-core": "2.0.14",
"@vue/language-server": "2.0.14",
"@vue/typescript-plugin": "2.0.14",
Expand Down
17 changes: 6 additions & 11 deletions extensions/vscode/src/common.ts
@@ -1,14 +1,14 @@
import { DiagnosticModel, VueInitializationOptions } from '@vue/language-server';
import * as vscode from 'vscode';
import * as lsp from '@volar/vscode';
import { quickPick } from '@volar/vscode/lib/common';
import type { VueInitializationOptions } from '@vue/language-server';
import * as fs from 'fs';
import * as path from 'path';
import * as semver from 'semver';
import * as vscode from 'vscode';
import { config } from './config';
import * as doctor from './features/doctor';
import * as nameCasing from './features/nameCasing';
import * as splitEditors from './features/splitEditors';
import * as semver from 'semver';
import * as fs from 'fs';
import * as path from 'path';
import { quickPick } from '@volar/vscode/lib/common';

let client: lsp.BaseLanguageClient;

Expand Down Expand Up @@ -437,13 +437,8 @@ async function getInitializationOptions(
hybridMode: boolean,
): Promise<VueInitializationOptions> {
return {
diagnosticModel: enabledHybridMode ? DiagnosticModel.Pull : DiagnosticModel.Push,
typescript: { tsdk: (await lsp.getTsdk(context)).tsdk },
maxFileSize: config.server.maxFileSize,
semanticTokensLegend: {
tokenTypes: [],
tokenModifiers: [],
},
vue: {
hybridMode,
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -21,7 +21,7 @@
"devDependencies": {
"@lerna-lite/cli": "latest",
"@lerna-lite/publish": "latest",
"@volar/language-service": "2.2.0-alpha.10",
"@volar/language-service": "2.2.0-alpha.12",
"@volar/tsl-config": "latest",
"tsl": "latest",
"typescript": "latest",
Expand Down
12 changes: 0 additions & 12 deletions packages/component-meta/lib/base.ts
Expand Up @@ -88,18 +88,6 @@ function createCheckerWorker(
}
return scriptSnapshots.get(fileName);
},
getLanguageId: fileName => {
if (parsedCommandLine.vueOptions.extensions.some(ext => fileName.endsWith(ext))) {
return 'vue';
}
if (parsedCommandLine.vueOptions.vitePressExtensions.some(ext => fileName.endsWith(ext))) {
return 'markdown';
}
if (parsedCommandLine.vueOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
return 'html';
}
return vue.resolveCommonLanguageId(fileName);
},
scriptIdToFileName: id => id,
fileNameToScriptId: id => id,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/component-meta/package.json
Expand Up @@ -12,7 +12,7 @@
"directory": "packages/component-meta"
},
"dependencies": {
"@volar/typescript": "2.2.0-alpha.10",
"@volar/typescript": "2.2.0-alpha.12",
"@vue/language-core": "2.0.14",
"path-browserify": "^1.0.1",
"vue-component-type-helpers": "2.0.14"
Expand Down
25 changes: 15 additions & 10 deletions packages/language-core/lib/languageModule.ts
Expand Up @@ -51,7 +51,7 @@ function getFileRegistryKey(
return JSON.stringify(values);
}

interface _Plugin extends LanguagePlugin<VueVirtualCode> {
export interface _Plugin extends LanguagePlugin<VueVirtualCode> {
getCanonicalFileName: (fileName: string) => string;
pluginContext: Parameters<VueLanguagePlugin>[0];
}
Expand Down Expand Up @@ -93,14 +93,19 @@ export function createVueLanguagePlugin(
return {
getCanonicalFileName,
pluginContext,
getLanguageId(scriptId) {
if (vueCompilerOptions.extensions.some(ext => scriptId.endsWith(ext))) {
return 'vue';
}
if (vueCompilerOptions.vitePressExtensions.some(ext => scriptId.endsWith(ext))) {
return 'markdown';
}
if (vueCompilerOptions.petiteVueExtensions.some(ext => scriptId.endsWith(ext))) {
return 'html';
}
},
createVirtualCode(fileId, languageId, snapshot) {
const isVueFile = vueCompilerOptions.extensions.some(ext => fileId.endsWith(ext))
|| (vueCompilerOptions.extensions.length && languageId === 'vue');
const isVitePressFile = vueCompilerOptions.vitePressExtensions.some(ext => fileId.endsWith(ext))
|| (vueCompilerOptions.vitePressExtensions.length && languageId === 'markdown');
const isPetiteVueFile = vueCompilerOptions.petiteVueExtensions.some(ext => fileId.endsWith(ext))
|| (vueCompilerOptions.petiteVueExtensions.length && languageId === 'html');
if (isVueFile || isVitePressFile || isPetiteVueFile) {
if (languageId === 'vue' || languageId === 'markdown' || languageId === 'html') {
const fileName = getFileName(fileId);
const projectVersion = getProjectVersion();
if (projectVersion !== canonicalRootFileNamesVersion) {
Expand All @@ -122,9 +127,9 @@ export function createVueLanguagePlugin(
languageId,
snapshot,
vueCompilerOptions,
isPetiteVueFile
languageId === 'html'
? [petiteVueSfcPlugin, ...basePlugins]
: isVitePressFile
: languageId === 'markdown'
? [vitePressSfcPlugin, ...basePlugins]
: [vueSfcPlugin, ...basePlugins],
ts,
Expand Down
22 changes: 19 additions & 3 deletions packages/language-core/lib/virtualFile/computedFiles.ts
@@ -1,4 +1,4 @@
import { VirtualCode, buildMappings, resolveCommonLanguageId, toString } from '@volar/language-core';
import { VirtualCode, buildMappings, toString } from '@volar/language-core';
import { computed } from 'computeds';
import type * as ts from 'typescript';
import type { Code, Sfc, SfcBlock, VueLanguagePlugin } from '../types';
Expand Down Expand Up @@ -57,7 +57,7 @@ export function computedFiles(
if (!file.parentCodeId) {
embeddedCodes.push({
id: file.id,
languageId: resolveCommonLanguageId(`/dummy.${file.lang}`),
languageId: resolveCommonLanguageId(file.lang),
linkedCodeMappings: file.linkedCodeMappings,
snapshot,
mappings,
Expand All @@ -71,7 +71,7 @@ export function computedFiles(
parent.embeddedCodes ??= [];
parent.embeddedCodes.push({
id: file.id,
languageId: resolveCommonLanguageId(`/dummy.${file.lang}`),
languageId: resolveCommonLanguageId(file.lang),
linkedCodeMappings: file.linkedCodeMappings,
snapshot,
mappings,
Expand Down Expand Up @@ -238,3 +238,19 @@ function fullDiffTextChangeRange(oldText: string, newText: string): ts.TextChang
}
}
}

export function resolveCommonLanguageId(lang: string) {
switch (lang) {
case 'js': return 'javascript';
case 'cjs': return 'javascript';
case 'mjs': return 'javascript';
case 'ts': return 'typescript';
case 'cts': return 'typescript';
case 'mts': return 'typescript';
case 'jsx': return 'javascriptreact';
case 'tsx': return 'typescriptreact';
case 'pug': return 'jade';
case 'md': return 'markdown';
}
return lang;
}
2 changes: 1 addition & 1 deletion packages/language-core/package.json
Expand Up @@ -12,7 +12,7 @@
"directory": "packages/language-core"
},
"dependencies": {
"@volar/language-core": "2.2.0-alpha.10",
"@volar/language-core": "2.2.0-alpha.12",
"@vue/compiler-dom": "^3.4.0",
"@vue/shared": "^3.4.0",
"computeds": "^0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/language-plugin-pug/package.json
Expand Up @@ -16,7 +16,7 @@
"@vue/language-core": "2.0.14"
},
"dependencies": {
"@volar/source-map": "2.2.0-alpha.10",
"@volar/source-map": "2.2.0-alpha.12",
"volar-service-pug": "0.0.40"
}
}

0 comments on commit 31c9148

Please sign in to comment.