Skip to content

Commit

Permalink
chore: update to Volar 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Aug 19, 2024
1 parent efba00b commit d24c984
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 268 deletions.
2 changes: 1 addition & 1 deletion extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@
"devDependencies": {
"@types/semver": "^7.5.3",
"@types/vscode": "^1.82.0",
"@volar/vscode": "~2.4.0-alpha.18",
"@volar/vscode": "~2.4.0",
"@vscode/vsce": "latest",
"@vue/language-core": "2.0.28",
"@vue/language-server": "2.0.28",
Expand Down
19 changes: 1 addition & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,13 @@
"@lerna-lite/publish": "latest",
"@tsslint/cli": "latest",
"@tsslint/config": "latest",
"@volar/language-service": "~2.4.0-alpha.18",
"@volar/language-service": "~2.4.0",
"typescript": "latest",
"vite": "latest",
"vitest": "latest"
},
"pnpm": {
"overrides": {
"@volar/kit": "https://pkg.pr.new/volarjs/volar.js/@volar/kit@ab44192",
"@volar/language-core": "https://pkg.pr.new/volarjs/volar.js/@volar/language-core@ab44192",
"@volar/language-server": "https://pkg.pr.new/volarjs/volar.js/@volar/language-server@ab44192",
"@volar/language-service": "https://pkg.pr.new/volarjs/volar.js/@volar/language-service@ab44192",
"@volar/source-map": "https://pkg.pr.new/volarjs/volar.js/@volar/source-map@ab44192",
"@volar/typescript": "https://pkg.pr.new/volarjs/volar.js/@volar/typescript@ab44192",
"@volar/vscode": "https://pkg.pr.new/volarjs/volar.js/@volar/vscode@ab44192",
"volar-service-css": "https://pkg.pr.new/volarjs/services/volar-service-css@f520ee3",
"volar-service-emmet": "https://pkg.pr.new/volarjs/services/volar-service-emmet@f520ee3",
"volar-service-html": "https://pkg.pr.new/volarjs/services/volar-service-html@f520ee3",
"volar-service-json": "https://pkg.pr.new/volarjs/services/volar-service-json@f520ee3",
"volar-service-markdown": "https://pkg.pr.new/volarjs/services/volar-service-markdown@f520ee3",
"volar-service-prettyhtml": "https://pkg.pr.new/volarjs/services/volar-service-prettyhtml@f520ee3",
"volar-service-pug": "https://pkg.pr.new/volarjs/services/volar-service-pug@f520ee3",
"volar-service-pug-beautify": "https://pkg.pr.new/volarjs/services/volar-service-pug-beautify@f520ee3",
"volar-service-typescript": "https://pkg.pr.new/volarjs/services/volar-service-typescript@f520ee3",
"volar-service-typescript-twoslash-queries": "https://pkg.pr.new/volarjs/services/volar-service-typescript-twoslash-queries@f520ee3",
"inquirer": "9.2.23"
}
}
Expand Down
137 changes: 59 additions & 78 deletions packages/component-meta/lib/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function createCheckerByJsonConfigBase(
checkerOptions: MetaCheckerOptions = {}
) {
rootDir = rootDir.replace(windowsPathReg, '/');
return createCheckerWorker(
return baseCreate(
ts,
() => vue.createParsedCommandLineByJson(ts, ts.sys, rootDir, json),
checkerOptions,
Expand All @@ -42,7 +42,7 @@ export function createCheckerBase(
checkerOptions: MetaCheckerOptions = {}
) {
tsconfig = tsconfig.replace(windowsPathReg, '/');
return createCheckerWorker(
return baseCreate(
ts,
() => vue.createParsedCommandLine(ts, ts.sys, tsconfig),
checkerOptions,
Expand All @@ -51,75 +51,28 @@ export function createCheckerBase(
);
}

function createCheckerWorker(
export function baseCreate(
ts: typeof import('typescript'),
loadParsedCommandLine: () => vue.ParsedCommandLine,
getCommandLine: () => vue.ParsedCommandLine,
checkerOptions: MetaCheckerOptions,
rootPath: string,
globalComponentName: string
) {

/**
* Original Host
*/

let parsedCommandLine = loadParsedCommandLine();
let fileNames = parsedCommandLine.fileNames.map(path => path.replace(windowsPathReg, '/'));
let commandLine = getCommandLine();
let fileNames = commandLine.fileNames.map(path => path.replace(windowsPathReg, '/'));
let projectVersion = 0;

const scriptSnapshots = new Map<string, ts.IScriptSnapshot>();
const projectHost: TypeScriptProjectHost = {
getCurrentDirectory: () => rootPath,
getProjectVersion: () => projectVersion.toString(),
getCompilationSettings: () => parsedCommandLine.options,
getCompilationSettings: () => commandLine.options,
getScriptFileNames: () => fileNames,
getProjectReferences: () => parsedCommandLine.projectReferences,
getScriptSnapshot: fileName => {
if (!scriptSnapshots.has(fileName)) {
const fileText = ts.sys.readFile(fileName);
if (fileText !== undefined) {
scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(fileText));
}
}
return scriptSnapshots.get(fileName);
},
getProjectReferences: () => commandLine.projectReferences,
};

return {
...baseCreate(ts, projectHost, parsedCommandLine.vueOptions, checkerOptions, globalComponentName),
updateFile(fileName: string, text: string) {
fileName = fileName.replace(windowsPathReg, '/');
scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text));
projectVersion++;
},
deleteFile(fileName: string) {
fileName = fileName.replace(windowsPathReg, '/');
fileNames = fileNames.filter(f => f !== fileName);
projectVersion++;
},
reload() {
parsedCommandLine = loadParsedCommandLine();
fileNames = parsedCommandLine.fileNames.map(path => path.replace(windowsPathReg, '/'));
this.clearCache();
},
clearCache() {
scriptSnapshots.clear();
projectVersion++;
},
};
}

export function baseCreate(
ts: typeof import('typescript'),
projectHost: TypeScriptProjectHost,
vueCompilerOptions: vue.VueCompilerOptions,
checkerOptions: MetaCheckerOptions,
globalComponentName: string
) {
const globalComponentSnapshot = ts.ScriptSnapshot.fromString('<script setup lang="ts"></script>');
const metaSnapshots: Record<string, ts.IScriptSnapshot> = {};
const scriptSnapshots = new Map<string, ts.IScriptSnapshot | undefined>();
const metaSnapshots = new Map<string, ts.IScriptSnapshot>();
const getScriptFileNames = projectHost.getScriptFileNames;
const getScriptSnapshot = projectHost.getScriptSnapshot;
projectHost.getScriptFileNames = () => {
const names = getScriptFileNames();
return [
Expand All @@ -129,20 +82,6 @@ export function baseCreate(
getMetaFileName(globalComponentName),
];
};
projectHost.getScriptSnapshot = fileName => {
if (isMetaFileName(fileName)) {
if (!metaSnapshots[fileName]) {
metaSnapshots[fileName] = ts.ScriptSnapshot.fromString(getMetaScriptContent(fileName));
}
return metaSnapshots[fileName];
}
else if (fileName === globalComponentName) {
return globalComponentSnapshot;
}
else {
return getScriptSnapshot(fileName);
}
};

const vueLanguagePlugin = vue.createVueLanguagePlugin2<string>(
ts,
Expand All @@ -153,7 +92,7 @@ export function baseCreate(
ts.sys.useCaseSensitiveFileNames
),
projectHost.getCompilationSettings(),
vueCompilerOptions
commandLine.vueOptions
);
const language = vue.createLanguage(
[
Expand All @@ -166,7 +105,30 @@ export function baseCreate(
],
new vue.FileMap(ts.sys.useCaseSensitiveFileNames),
fileName => {
const snapshot = projectHost.getScriptSnapshot(fileName);
let snapshot = scriptSnapshots.get(fileName);

if (fileName === globalComponentName) {
snapshot = globalComponentSnapshot;
}
else if (isMetaFileName(fileName)) {
if (!metaSnapshots.has(fileName)) {
metaSnapshots.set(fileName, ts.ScriptSnapshot.fromString(getMetaScriptContent(fileName)));
}
snapshot = metaSnapshots.get(fileName);
}
else {
if (!scriptSnapshots.has(fileName)) {
const fileText = ts.sys.readFile(fileName);
if (fileText !== undefined) {
scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(fileText));
}
else {
scriptSnapshots.set(fileName, undefined);
}
}
snapshot = scriptSnapshots.get(fileName);
}

if (snapshot) {
language.scripts.set(fileName, snapshot);
}
Expand All @@ -182,7 +144,7 @@ export function baseCreate(
const getScriptKind = languageServiceHost.getScriptKind?.bind(languageServiceHost);
languageServiceHost.getScriptKind = fileName => {
const scriptKind = getScriptKind!(fileName);
if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
if (commandLine.vueOptions.extensions.some(ext => fileName.endsWith(ext))) {
if (scriptKind === ts.ScriptKind.JS) {
return ts.ScriptKind.TS;
}
Expand All @@ -199,6 +161,25 @@ export function baseCreate(
return {
getExportNames,
getComponentMeta,
updateFile(fileName: string, text: string) {
fileName = fileName.replace(windowsPathReg, '/');
scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text));
projectVersion++;
},
deleteFile(fileName: string) {
fileName = fileName.replace(windowsPathReg, '/');
fileNames = fileNames.filter(f => f !== fileName);
projectVersion++;
},
reload() {
commandLine = getCommandLine();
fileNames = commandLine.fileNames.map(path => path.replace(windowsPathReg, '/'));
this.clearCache();
},
clearCache() {
scriptSnapshots.clear();
projectVersion++;
},
__internal__: {
tsLs,
},
Expand All @@ -210,7 +191,7 @@ export function baseCreate(

function getMetaFileName(fileName: string) {
return (
vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))
commandLine.vueOptions.extensions.some(ext => fileName.endsWith(ext))
? fileName
: fileName.substring(0, fileName.lastIndexOf('.'))
) + '.meta.ts';
Expand All @@ -229,7 +210,7 @@ interface ComponentMeta<T> {
exposed: ComponentExposed<T>;
};
${vueCompilerOptions.target < 3 ? vue2TypeHelpersCode : typeHelpersCode}
${commandLine.vueOptions.target < 3 ? vue2TypeHelpersCode : typeHelpersCode}
`.trim();
return code;
}
Expand Down Expand Up @@ -321,11 +302,11 @@ ${vueCompilerOptions.target < 3 ? vue2TypeHelpersCode : typeHelpersCode}

// fill defaults
const printer = ts.createPrinter(checkerOptions.printer);
const snapshot = projectHost.getScriptSnapshot(componentPath)!;
const snapshot = language.scripts.get(componentPath)?.snapshot!;

const vueFile = language.scripts.get(componentPath)?.generated?.root;
const vueDefaults = vueFile && exportName === 'default'
? (vueFile instanceof vue.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts, vueCompilerOptions) : {})
? (vueFile instanceof vue.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts, commandLine.vueOptions) : {})
: {};
const tsDefaults = !vueFile ? readTsComponentDefaultProps(
componentPath.substring(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
Expand Down
2 changes: 1 addition & 1 deletion packages/component-meta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"directory": "packages/component-meta"
},
"dependencies": {
"@volar/typescript": "~2.4.0-alpha.18",
"@volar/typescript": "~2.4.0",
"@vue/language-core": "2.0.28",
"path-browserify": "^1.0.1",
"vue-component-type-helpers": "2.0.28"
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"directory": "packages/language-core"
},
"dependencies": {
"@volar/language-core": "~2.4.0-alpha.18",
"@volar/language-core": "~2.4.0",
"@vue/compiler-dom": "^3.4.0",
"@vue/shared": "^3.4.0",
"computeds": "^0.0.1",
Expand All @@ -25,7 +25,7 @@
"@types/minimatch": "^5.1.2",
"@types/node": "latest",
"@types/path-browserify": "^1.0.1",
"@volar/typescript": "~2.4.0-alpha.18",
"@volar/typescript": "~2.4.0",
"@vue/compiler-sfc": "^3.4.0"
},
"peerDependencies": {
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 @@ -16,7 +16,7 @@
"@vue/language-core": "2.0.28"
},
"dependencies": {
"@volar/source-map": "~2.4.0-alpha.18",
"volar-service-pug": "0.0.59"
"@volar/source-map": "~2.4.0",
"volar-service-pug": "0.0.61"
}
}
2 changes: 1 addition & 1 deletion packages/language-server/lib/hybridModeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function createHybridModeProject(
setup(_server) {
server = _server;
onSomePipeReadyCallbacks.push(() => {
server.languageFeatures.refreshDiagnostics(false);
server.languageFeatures.requestRefresh(false);
});
server.fileWatcher.onDidChangeWatchedFiles(({ changes }) => {
for (const change of changes) {
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"directory": "packages/language-server"
},
"dependencies": {
"@volar/language-core": "~2.4.0-alpha.18",
"@volar/language-server": "~2.4.0-alpha.18",
"@volar/language-core": "~2.4.0",
"@volar/language-server": "~2.4.0",
"@vue/language-core": "2.0.28",
"@vue/language-service": "2.0.28",
"@vue/typescript-plugin": "2.0.28",
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 @@ -16,31 +16,31 @@
"update-html-data": "node ./scripts/update-html-data.js"
},
"dependencies": {
"@volar/language-core": "~2.4.0-alpha.18",
"@volar/language-service": "~2.4.0-alpha.18",
"@volar/typescript": "~2.4.0-alpha.18",
"@volar/language-core": "~2.4.0",
"@volar/language-service": "~2.4.0",
"@volar/typescript": "~2.4.0",
"@vue/compiler-dom": "^3.4.0",
"@vue/language-core": "2.0.28",
"@vue/shared": "^3.4.0",
"@vue/typescript-plugin": "2.0.28",
"computeds": "^0.0.1",
"path-browserify": "^1.0.1",
"volar-service-css": "0.0.59",
"volar-service-emmet": "0.0.59",
"volar-service-html": "0.0.59",
"volar-service-json": "0.0.59",
"volar-service-pug": "0.0.59",
"volar-service-pug-beautify": "0.0.59",
"volar-service-typescript": "0.0.59",
"volar-service-typescript-twoslash-queries": "0.0.59",
"volar-service-css": "0.0.61",
"volar-service-emmet": "0.0.61",
"volar-service-html": "0.0.61",
"volar-service-json": "0.0.61",
"volar-service-pug": "0.0.61",
"volar-service-pug-beautify": "0.0.61",
"volar-service-typescript": "0.0.61",
"volar-service-typescript-twoslash-queries": "0.0.61",
"vscode-html-languageservice": "^5.2.0",
"vscode-languageserver-textdocument": "^1.0.11",
"vscode-uri": "^3.0.8"
},
"devDependencies": {
"@types/node": "latest",
"@types/path-browserify": "latest",
"@volar/kit": "~2.4.0-alpha.18",
"@volar/kit": "~2.4.0",
"vscode-languageserver-protocol": "^3.17.5"
}
}
1 change: 0 additions & 1 deletion packages/language-service/tests/utils/createTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function createTester(rootUri: URI) {
getProjectVersion: () => '0',
getScriptFileNames: () => parsedCommandLine.fileNames,
getCompilationSettings: () => parsedCommandLine.options,
getScriptSnapshot,
};
const vueLanguagePlugin = createVueLanguagePlugin2(
ts,
Expand Down
2 changes: 1 addition & 1 deletion packages/tsc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"vue-tsc": "./bin/vue-tsc.js"
},
"dependencies": {
"@volar/typescript": "~2.4.0-alpha.18",
"@volar/typescript": "~2.4.0",
"@vue/language-core": "2.0.28",
"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 @@ -12,7 +12,7 @@
"directory": "packages/typescript-plugin"
},
"dependencies": {
"@volar/typescript": "~2.4.0-alpha.18",
"@volar/typescript": "~2.4.0",
"@vue/language-core": "2.0.28",
"@vue/shared": "^3.4.0"
},
Expand Down
Loading

0 comments on commit d24c984

Please sign in to comment.