Skip to content

Commit

Permalink
chore: update Volar
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 8, 2024
1 parent 9ad4954 commit a6cb6bf
Show file tree
Hide file tree
Showing 21 changed files with 632 additions and 697 deletions.
2 changes: 1 addition & 1 deletion extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
"devDependencies": {
"@types/semver": "^7.5.3",
"@types/vscode": "^1.82.0",
"@volar/vscode": "~2.3.0-alpha.4",
"@volar/vscode": "~2.3.0-alpha.14",
"@vue/language-core": "2.0.19",
"@vue/language-server": "2.0.19",
"@vue/typescript-plugin": "2.0.19",
Expand Down
6 changes: 2 additions & 4 deletions extensions/vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,7 @@ async function getInitializationOptions(
hybridMode: boolean
): Promise<VueInitializationOptions> {
return {
typescript: { tsdk: (await lsp.getTsdk(context)).tsdk },
vue: {
hybridMode,
},
typescript: { tsdk: (await lsp.getTsdk(context))!.tsdk },
vue: { hybridMode },
};
};
2 changes: 1 addition & 1 deletion extensions/vscode/src/features/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
}

// check tsdk version should be higher than 5.0.0
const tsdk = await getTsdk(context);
const tsdk = (await getTsdk(context))!;
if (tsdk.version && !semver.gte(tsdk.version, '5.0.0')) {
problems.push({
title: 'Requires TSDK 5.0 or higher',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@lerna-lite/publish": "latest",
"@tsslint/cli": "latest",
"@tsslint/config": "latest",
"@volar/language-service": "~2.3.0-alpha.4",
"@volar/language-service": "~2.3.0-alpha.14",
"@volar/tsslint-config": "latest",
"typescript": "latest",
"vite": "latest",
Expand Down
2 changes: 1 addition & 1 deletion packages/component-meta/lib/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ function createSchemaResolvers(
if (sourceFile?.generated) {
const script = sourceFile.generated.languagePlugin.typescript?.getServiceScript(sourceFile.generated.root);
if (script) {
for (const [source, [_, map]] of language.maps.forEach(script.code)) {
for (const [source, _, map] of language.maps.forEach(script.code)) {
for (const [start] of map.getSourceOffsets(declaration.getStart())) {
for (const [end] of map.getSourceOffsets(declaration.getEnd())) {
return {
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.3.0-alpha.4",
"@volar/typescript": "~2.3.0-alpha.14",
"@vue/language-core": "2.0.19",
"path-browserify": "^1.0.1",
"vue-component-type-helpers": "2.0.19"
Expand Down
32 changes: 20 additions & 12 deletions packages/language-core/lib/virtualFile/computedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,32 @@ function computedPluginEmbeddedCodes(

return computed(() => {
return codes().map(_file => {

const { code, snapshot } = _file();
const mappings = buildMappings(code.content);
const mappings = buildMappings(code.content.map<Code>(segment => {
if (typeof segment === 'string') {
return segment;
}
const source = segment[1];
if (source === undefined) {
return segment;
}
const block = nameToBlock()[source];
if (!block) {
console.warn('Unable to find block: ' + source);
return segment;
}
return [
segment[0],
undefined,
segment[2] + block.startTagEnd,
segment[3],
];
}));
const newMappings: typeof mappings = [];
let lastValidMapping: typeof mappings[number] | undefined;

for (let i = 0; i < mappings.length; i++) {
const mapping = mappings[i];
if (mapping.source !== undefined) {
const block = nameToBlock()[mapping.source];
if (block) {
mapping.sourceOffsets = mapping.sourceOffsets.map(offset => offset + block.startTagEnd);
}
else {
// ignore
}
mapping.source = undefined;
}
if (mapping.data.__combineOffsetMapping !== undefined) {
const offsetMapping = mappings[i - mapping.data.__combineOffsetMapping];
if (typeof offsetMapping === 'string' || !offsetMapping) {
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 @@ -12,7 +12,7 @@
"directory": "packages/language-core"
},
"dependencies": {
"@volar/language-core": "~2.3.0-alpha.4",
"@volar/language-core": "~2.3.0-alpha.14",
"@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 @@ -16,7 +16,7 @@
"@vue/language-core": "2.0.19"
},
"dependencies": {
"@volar/source-map": "~2.3.0-alpha.4",
"volar-service-pug": "0.0.49"
"@volar/source-map": "~2.3.0-alpha.14",
"volar-service-pug": "0.0.50"
}
}
10 changes: 7 additions & 3 deletions packages/language-server/lib/hybridModeProject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LanguagePlugin, LanguageServer, Project, ProviderResult } from '@volar/language-server';
import type { LanguagePlugin, LanguageServer, LanguageServerProject, ProviderResult } from '@volar/language-server';
import { createLanguageServiceEnvironment } from '@volar/language-server/lib/project/simpleProject';
import { createLanguage } from '@vue/language-core';
import { Disposable, LanguageService, LanguageServiceEnvironment, createLanguageService, createUriMap } from '@vue/language-service';
Expand All @@ -20,15 +20,19 @@ export type GetLanguagePlugin<T> = (params: {
export function createHybridModeProject(
sys: ts.System,
getLanguagePlugins: GetLanguagePlugin<URI>
): Project {
): LanguageServerProject {
let initialized = false;
let simpleLs: Promise<LanguageService> | undefined;
let serviceEnv: LanguageServiceEnvironment | undefined;
let server: LanguageServer;

const tsconfigProjects = createUriMap<Promise<LanguageService>>(sys.useCaseSensitiveFileNames);

return {
async getLanguageService(server, uri) {
setup(_server) {
server = _server;
},
async getLanguageService(uri) {
if (!initialized) {
initialized = true;
initialize(server);
Expand Down
14 changes: 7 additions & 7 deletions packages/language-server/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ connection.onInitialize(params => {

const result = server.initialize(
params,
getVueLanguageServicePlugins(
tsdk.typescript,
env => envToVueOptions.get(env)!,
getTsPluginClient,
hybridMode
),
hybridMode
? createHybridModeProject(tsdk.typescript.sys, getLanguagePlugins)
: createTypeScriptProject(tsdk.typescript, tsdk.diagnosticMessages, (env, ctx) => getLanguagePlugins({
Expand All @@ -101,6 +95,12 @@ connection.onInitialize(params => {
sys: ctx.sys,
asFileName: ctx.asFileName,
})),
getVueLanguageServicePlugins(
tsdk.typescript,
env => envToVueOptions.get(env)!,
getTsPluginClient,
hybridMode
),
{
pullModelDiagnostics: hybridMode,
}
Expand Down Expand Up @@ -156,5 +156,5 @@ connection.onRequest(GetConnectedNamedPipeServerRequest.type, async fileName =>
});

async function getService(uri: URI) {
return (await server.project.getLanguageService(server, uri));
return (await server.project.getLanguageService(uri));
}
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.3.0-alpha.4",
"@volar/language-server": "~2.3.0-alpha.4",
"@volar/language-core": "~2.3.0-alpha.14",
"@volar/language-server": "~2.3.0-alpha.14",
"@vue/language-core": "2.0.19",
"@vue/language-service": "2.0.19",
"@vue/typescript-plugin": "2.0.19",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function create(
}
ast = getAst(ts, fileName, virtualCode.snapshot, serviceScript.scriptKind);
let mapped = false;
for (const [_1, [_2, map]] of context.language.maps.forEach(virtualCode)) {
for (const [_1, _2, map] of context.language.maps.forEach(virtualCode)) {
for (const [sourceOffset] of map.getSourceOffsets(document.offsetAt(selection))) {
sourceCodeOffset = sourceOffset;
mapped = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function create(
}

for (const [pointerPosition, hoverOffset] of hoverOffsets) {
for (const [_1, [_2, map]] of context.language.maps.forEach(virtualCode)) {
for (const [_1, _2, map] of context.language.maps.forEach(virtualCode)) {
for (const [sourceOffset] of map.getSourceOffsets(hoverOffset)) {
const quickInfo = await tsPluginClient?.getQuickInfoAtPosition(sourceScript.generated.root.fileName, sourceOffset);
if (quickInfo) {
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.3.0-alpha.4",
"@volar/language-service": "~2.3.0-alpha.4",
"@volar/typescript": "~2.3.0-alpha.4",
"@volar/language-core": "~2.3.0-alpha.14",
"@volar/language-service": "~2.3.0-alpha.14",
"@volar/typescript": "~2.3.0-alpha.14",
"@vue/compiler-dom": "^3.4.0",
"@vue/language-core": "2.0.19",
"@vue/shared": "^3.4.0",
"@vue/typescript-plugin": "2.0.19",
"computeds": "^0.0.1",
"path-browserify": "^1.0.1",
"volar-service-css": "0.0.49",
"volar-service-emmet": "0.0.49",
"volar-service-html": "0.0.49",
"volar-service-json": "0.0.49",
"volar-service-pug": "0.0.49",
"volar-service-pug-beautify": "0.0.49",
"volar-service-typescript": "0.0.49",
"volar-service-typescript-twoslash-queries": "0.0.49",
"volar-service-css": "0.0.50",
"volar-service-emmet": "0.0.50",
"volar-service-html": "0.0.50",
"volar-service-json": "0.0.50",
"volar-service-pug": "0.0.50",
"volar-service-pug-beautify": "0.0.50",
"volar-service-typescript": "0.0.50",
"volar-service-typescript-twoslash-queries": "0.0.50",
"vscode-html-languageservice": "npm:@johnsoncodehk/[email protected]",
"vscode-languageserver-textdocument": "^1.0.11",
"vscode-uri": "^3.0.8"
},
"devDependencies": {
"@types/node": "latest",
"@types/path-browserify": "latest",
"@volar/kit": "~2.3.0-alpha.4",
"@volar/kit": "~2.3.0-alpha.14",
"vscode-languageserver-protocol": "^3.17.5"
}
}
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.3.0-alpha.4",
"@volar/typescript": "~2.3.0-alpha.14",
"@vue/language-core": "2.0.19",
"semver": "^7.5.4"
},
Expand Down
Loading

0 comments on commit a6cb6bf

Please sign in to comment.