Skip to content

Commit

Permalink
feat(vscode): report #3942 in doctor
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Mar 3, 2024
1 parent f4183dc commit 93ed370
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
16 changes: 15 additions & 1 deletion extensions/vscode/src/features/doctor.ts
@@ -1,5 +1,5 @@
import { getTsdk } from '@volar/vscode';
import { ParseSFCRequest } from '@vue/language-server';
import { GetConnectedNamedPipeServerRequest, ParseSFCRequest } from '@vue/language-server';
import * as semver from 'semver';
import * as vscode from 'vscode';
import type { BaseLanguageClient } from 'vscode-languageclient';
Expand Down Expand Up @@ -257,6 +257,20 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
});
}

// #3942
const namedPipe = await client.sendRequest(GetConnectedNamedPipeServerRequest.type, fileUri.fsPath.replace(/\\/g, '/'));
if (namedPipe?.serverKind === 0) {
problems.push({
title: 'Missing jsconfig/tsconfig',
message: [
'The current file does not have a matching tsconfig/jsconfig, and extension version 2.0 will not work properly for this at the moment.',
'To avoid this problem, you can create a jsconfig in the project root, or downgrade to 1.8.27.',
'',
'Issue: https://github.com/vuejs/language-tools/issues/3942',
].join('\n'),
});
}

// check outdated vue language plugins
// check node_modules has more than one vue versions
// check ESLint, Prettier...
Expand Down
10 changes: 10 additions & 0 deletions packages/language-server/lib/protocol.ts
Expand Up @@ -39,3 +39,13 @@ export namespace ParseSFCRequest {
export type ErrorType = never;
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('vue/parseSfc');
}

export namespace GetConnectedNamedPipeServerRequest {
export type ParamsType = string;
export type ResponseType = {
path: string,
serverKind: number,
} | undefined;
export type ErrorType = never;
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('vue/namedPipeServer');
}
8 changes: 8 additions & 0 deletions packages/language-server/node.ts
Expand Up @@ -5,6 +5,7 @@ import { ServiceEnvironment, convertAttrName, convertTagName, createVueServicePl
import { DetectNameCasingRequest, GetConvertAttrCasingEditsRequest, GetConvertTagCasingEditsRequest, ParseSFCRequest } from './lib/protocol';
import type { VueInitializationOptions } from './lib/types';
import * as tsPluginClient from '@vue/typescript-plugin/lib/client';
import { GetConnectedNamedPipeServerRequest } from './lib/protocol';

export const connection: Connection = createConnection();

Expand Down Expand Up @@ -122,6 +123,13 @@ connection.onRequest(GetConvertAttrCasingEditsRequest.type, async params => {
}
});

connection.onRequest(GetConnectedNamedPipeServerRequest.type, async fileName => {
const connected = await tsPluginClient.connectForFile(fileName);
if (connected) {
return connected[1];
}
});

async function getService(uri: string) {
return (await server.projects.getProject(uri)).getLanguageService();
}
11 changes: 6 additions & 5 deletions packages/typescript-plugin/lib/client.ts
Expand Up @@ -81,17 +81,18 @@ export function getElementAttrs(
}

async function sendRequest<T>(request: Request) {
const client = await connectForFile(request.args[0]);
if (!client) {
const connected = await connectForFile(request.args[0]);
if (!connected) {
console.warn('[Vue Named Pipe Client] No server found for', request.args[0]);
return;
}
const [client] = connected;
const result = await sendRequestWorker<T>(request, client);
client.end();
return result;
}

async function connectForFile(fileName: string) {
export async function connectForFile(fileName: string) {
if (!fs.existsSync(pipeTable)) {
return;
}
Expand All @@ -106,15 +107,15 @@ async function connectForFile(fileName: string) {
if (client) {
const response = await sendRequestWorker<boolean>({ type: 'containsFile', args: [fileName] }, client);
if (response) {
return client;
return [client, server] as const;
}
}
}
for (const server of inferredServers) {
if (!path.relative(server.currentDirectory, fileName).startsWith('..')) {
const client = await connect(server.path);
if (client) {
return client;
return [client, server] as const;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-plugin/lib/server.ts
Expand Up @@ -81,7 +81,7 @@ export function startNamedPipeServer(serverKind: ts.server.ProjectKind, currentD
connection.on('error', err => console.error('[Vue Named Pipe Server]', err.message));
});

clearupPipeTable();
cleanupPipeTable();

if (!fs.existsSync(pipeTable)) {
fs.writeFileSync(pipeTable, JSON.stringify([] satisfies NamedPipeServer[]));
Expand All @@ -101,7 +101,7 @@ export function startNamedPipeServer(serverKind: ts.server.ProjectKind, currentD
server.listen(pipeFile);
}

function clearupPipeTable() {
function cleanupPipeTable() {
if (!fs.existsSync(pipeTable)) {
return;
}
Expand Down

0 comments on commit 93ed370

Please sign in to comment.