From 4e2bccbb77da049c127243a1ed3a52b8ff67b98f Mon Sep 17 00:00:00 2001 From: Roland Grunberg Date: Tue, 14 May 2024 15:34:29 -0400 Subject: [PATCH] Fall back to 'stdio' transport if 'pipe' is likely to fail. - If generateRandomPipeName fails, then the pipe transport will fail and we should instead fall back to 'stdio' transport Signed-off-by: Roland Grunberg --- src/javaServerStarter.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/javaServerStarter.ts b/src/javaServerStarter.ts index 7b28624d3..231229af1 100644 --- a/src/javaServerStarter.ts +++ b/src/javaServerStarter.ts @@ -6,12 +6,13 @@ import * as net from 'net'; import * as os from 'os'; import * as path from 'path'; import { ExtensionContext, version, workspace } from 'vscode'; -import { Executable, ExecutableOptions, StreamInfo, TransportKind } from 'vscode-languageclient/node'; +import { Executable, ExecutableOptions, StreamInfo, TransportKind, generateRandomPipeName } from 'vscode-languageclient/node'; import { logger } from './log'; import { addLombokParam, isLombokSupportEnabled } from './lombokSupport'; import { RequirementsData } from './requirements'; import { IS_WORKSPACE_VMARGS_ALLOWED, getJavaEncoding, getJavaagentFlag, getKey, isInWorkspaceFolder } from './settings'; import { deleteDirectory, ensureExists, getJavaConfiguration, getTimestamp } from './utils'; +import { log } from 'console'; // eslint-disable-next-line no-var declare var v8debug; @@ -50,9 +51,16 @@ export function prepareExecutable(requirements: RequirementsData, workspacePath, executable.command = path.resolve(`${requirements.tooling_jre}/bin/java`); executable.args = prepareParams(requirements, workspacePath, context, isSyntaxServer); const transportKind = getJavaConfiguration().get('transport'); + switch (transportKind) { case 'pipe': executable.transport = TransportKind.pipe; + try { + generateRandomPipeName(); + } catch (error) { + logger.warn(`Falling back to 'stdio' (from 'pipe') due to : ${error}`); + executable.transport = TransportKind.stdio; + } break; case 'stdio': executable.transport = TransportKind.stdio;