Skip to content

Commit

Permalink
fix(doctor): cannot resolve extends vueCompilerOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Oct 9, 2022
1 parent 77ce7e6 commit a471696
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
23 changes: 17 additions & 6 deletions extensions/vscode-vue-language-features/src/features/doctor.ts
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import * as semver from 'semver';
import { BaseLanguageClient } from 'vscode-languageclient';
import { GetMatchTsConfigRequest, ParseSFCRequest } from '@volar/vue-language-server';
import { GetMatchTsConfigRequest, ParseSFCRequest, GetVueCompilerOptionsRequest } from '@volar/vue-language-server';

const scheme = 'vue-doctor';
const knownValidSyntanxHighlightExtensions = {
Expand Down Expand Up @@ -80,9 +80,16 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
async function getProblems(fileUri: vscode.Uri) {

const workspaceFolder = vscode.workspace.workspaceFolders?.find(f => fileUri.path.startsWith(f.uri.path))?.uri.fsPath ?? vscode.workspace.rootPath!;
const tsconfig = await client.sendRequest(GetMatchTsConfigRequest.type, { uri: fileUri.toString() });
const vueDoc = vscode.workspace.textDocuments.find(doc => doc.fileName === fileUri.fsPath);
const sfc = vueDoc ? await client.sendRequest(ParseSFCRequest.type, vueDoc.getText()) : undefined;
const [
tsconfig,
vueOptions,
sfc,
] = await Promise.all([
client.sendRequest(GetMatchTsConfigRequest.type, { uri: fileUri.toString() }),
client.sendRequest(GetVueCompilerOptionsRequest.type, { uri: fileUri.toString() }),
vueDoc ? client.sendRequest(ParseSFCRequest.type, vueDoc.getText()) : undefined,
]);
const vueVersion = getWorkspacePackageJson(workspaceFolder, 'vue')?.version;
const problems: {
title: string;
Expand All @@ -100,13 +107,17 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
// check vue version < 3 but missing vueCompilerOptions.target
if (vueVersion) {
const vueVersionNumber = semver.gte(vueVersion, '3.0.0') ? 3 : semver.gte(vueVersion, '2.7.0') ? 2.7 : 2;
const targetVersionNumber = tsconfig?.raw?.vueCompilerOptions?.target ?? 3;
const targetVersionNumber = vueOptions?.target ?? 3;
const lines = [
`Target version not match, you can specify the target version in \`vueCompilerOptions.target\` in tsconfig.json / jsconfig.json. (expected \`"target": ${vueVersionNumber}\`)`,
'',
'- Vue version: ' + vueVersion,
'- tsconfig: ' + (tsconfig?.fileName ?? 'Not found'),
'- tsconfig target: ' + targetVersionNumber + (tsconfig?.raw?.vueCompilerOptions?.target !== undefined ? '' : ' (default)'),
'- tsconfig target: ' + targetVersionNumber + (vueOptions?.target !== undefined ? '' : ' (default)'),
'- vueCompilerOptions:',
'```json',
JSON.stringify(vueOptions, undefined, 2),
'```',
];
if (vueVersionNumber !== targetVersionNumber) {
problems.push({
Expand Down Expand Up @@ -153,7 +164,7 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
// check using pug but don't install @volar/vue-language-plugin-pug
if (
sfc?.descriptor.template?.lang === 'pug'
&& !tsconfig?.raw?.vueCompilerOptions?.plugins?.includes('@volar/vue-language-plugin-pug')
&& !vueOptions?.plugins?.includes('@volar/vue-language-plugin-pug')
) {
problems.push({
title: '`@volar/vue-language-plugin-pug` missing',
Expand Down
1 change: 0 additions & 1 deletion packages/language-server/src/features/customFeatures.ts
Expand Up @@ -14,7 +14,6 @@ export function register(
if (project) {
return {
fileName: project.tsconfig,
raw: project.project?.getParsedCommandLine().raw,
};
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/src/protocol.ts
Expand Up @@ -25,7 +25,7 @@ export namespace FindFileReferenceRequest {

export namespace GetMatchTsConfigRequest {
export type ParamsType = vscode.TextDocumentIdentifier;
export type ResponseType = { fileName: string, raw: any; } | null | undefined;
export type ResponseType = { fileName: string } | null | undefined;
export type ErrorType = never;
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/tsconfig');
}
Expand Down
6 changes: 3 additions & 3 deletions packages/language-server/src/utils/workspaces.ts
Expand Up @@ -112,7 +112,7 @@ export function createWorkspaces(
return;

const req = ++documentUpdatedReq;
const delay = await configurationHost?.getConfiguration<number>('volar.diagnostics.delay');
const delay = await configurationHost?.getConfiguration<number>('volar.diagnostics.delay') ?? 200;
const cancel = cancelTokenHost.createCancellactionToken({
get isCancellationRequested() {
return req !== documentUpdatedReq;
Expand All @@ -124,14 +124,14 @@ export function createWorkspaces(

if (changeDoc) {

await shared.sleep(delay ?? 200);
await shared.sleep(delay);

await sendDocumentDiagnostics(changeDoc.uri, changeDoc.version, cancel);
}

for (const doc of otherDocs) {

await shared.sleep(delay ?? 200);
await shared.sleep(delay);

await sendDocumentDiagnostics(doc.uri, doc.version, cancel);

Expand Down
Expand Up @@ -4,7 +4,7 @@ import * as shared from '@volar/shared';
import * as vue from '@volar/vue-language-service';
import * as vue2 from '@volar/vue-language-core';
import * as nameCasing from '@volar/vue-language-service';
import { DetectNameCasingRequest, GetConvertAttrCasingEditsRequest, GetConvertTagCasingEditsRequest, ParseSFCRequest } from './protocol';
import { DetectNameCasingRequest, GetConvertAttrCasingEditsRequest, GetConvertTagCasingEditsRequest, ParseSFCRequest, GetVueCompilerOptionsRequest } from './protocol';
import { VueServerInitializationOptions } from './types';
import type * as ts from 'typescript/lib/tsserverlibrary';

Expand Down Expand Up @@ -51,6 +51,12 @@ const plugin: LanguageServerPlugin<VueServerInitializationOptions, vue.LanguageS
},
onInitialize(connection, getService) {

connection.onRequest(GetVueCompilerOptionsRequest.type, async params => {
const languageService = await getService(params.uri);
const host = languageService.context.host as vue.LanguageServiceHost;
return host.getVueCompilationSettings?.();
});

connection.onRequest(DetectNameCasingRequest.type, async params => {
const languageService = await getService(params.textDocument.uri);
return nameCasing.detect(languageService.context, params.textDocument.uri);
Expand Down
7 changes: 7 additions & 0 deletions vue-language-tools/vue-language-server/src/protocol.ts
@@ -1,6 +1,13 @@
import * as vscode from 'vscode-languageserver-protocol';
import { TagNameCasing, AttrNameCasing, SFCParseResult } from '@volar/vue-language-service';

export namespace GetVueCompilerOptionsRequest {
export type ParamsType = vscode.TextDocumentIdentifier;
export type ResponseType = any | null | undefined;
export type ErrorType = never;
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/vueCompilerOptions');
}

export namespace DetectNameCasingRequest {
export type ParamsType = {
textDocument: vscode.TextDocumentIdentifier,
Expand Down

0 comments on commit a471696

Please sign in to comment.