From 24effe7504b41e5475dec0ccfd66c339e75a5164 Mon Sep 17 00:00:00 2001 From: Jiaaming <2455951489@qq.com> Date: Mon, 5 Aug 2024 13:54:59 +0800 Subject: [PATCH 1/2] Fix: language server generatePipepath error --- extension/src/languageServer/languageServer.ts | 4 ++++ .../java/com/microsoft/gradle/GradleLanguageServer.java | 6 +----- .../java/com/github/badsyntax/gradle/GradleServer.java | 7 +++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/extension/src/languageServer/languageServer.ts b/extension/src/languageServer/languageServer.ts index 35d88d14f..42e255bb8 100644 --- a/extension/src/languageServer/languageServer.ts +++ b/extension/src/languageServer/languageServer.ts @@ -23,6 +23,10 @@ export async function startLanguageClientAndWaitForConnection( rootProjectsStore: RootProjectsStore, languageServerPipePath: string ): Promise { + if (languageServerPipePath === "") { + isLanguageServerStarted = false; + return; + } void vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (progress) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars return new Promise(async (resolve) => { diff --git a/gradle-language-server/src/main/java/com/microsoft/gradle/GradleLanguageServer.java b/gradle-language-server/src/main/java/com/microsoft/gradle/GradleLanguageServer.java index 0edaaf8b3..9c24cc000 100644 --- a/gradle-language-server/src/main/java/com/microsoft/gradle/GradleLanguageServer.java +++ b/gradle-language-server/src/main/java/com/microsoft/gradle/GradleLanguageServer.java @@ -16,7 +16,6 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; -import org.apache.commons.lang3.StringUtils; import org.eclipse.lsp4j.CompletionOptions; import org.eclipse.lsp4j.DocumentFilter; import org.eclipse.lsp4j.ExecuteCommandOptions; @@ -43,9 +42,6 @@ public class GradleLanguageServer implements LanguageServer, LanguageClientAware public static void main(String[] args) { GradleLanguageServer server = new GradleLanguageServer(); - if (StringUtils.isBlank(args[0])) { - server.exit(); - } try { NamedPipeStream pipeStream = new NamedPipeStream(args[0]); @@ -55,7 +51,7 @@ public static void main(String[] args) { server.connect(launcher.getRemoteProxy()); launcher.startListening(); } catch (IOException e) { - server.exit(); + throw new RuntimeException("Gradle language server start failed", e); } } diff --git a/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleServer.java b/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleServer.java index a4e05a986..2629c98d9 100644 --- a/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleServer.java +++ b/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleServer.java @@ -1,6 +1,7 @@ package com.github.badsyntax.gradle; import com.github.badsyntax.gradle.utils.Utils; +import com.google.common.base.Strings; import com.microsoft.gradle.GradleLanguageServer; import io.grpc.Server; import io.grpc.ServerBuilder; @@ -62,8 +63,10 @@ public static void main(String[] args) throws Exception { int taskServerPort = Integer.parseInt(Utils.validateRequiredParam(params, "port")); startTaskServerThread(taskServerPort); - String languageServerPipePath = Utils.validateRequiredParam(params, "languageServerPipePath"); - startLanguageServerThread(languageServerPipePath); + String languageServerPipePath = params.get("languageServerPipePath"); + if (!Strings.isNullOrEmpty(languageServerPipePath)) { + startLanguageServerThread(languageServerPipePath); + } boolean startBuildServer = Boolean.parseBoolean(Utils.validateRequiredParam(params, "startBuildServer")); if (startBuildServer) { From 71f1c65c614b3fba39b1c4836ef7e5933ef329a6 Mon Sep 17 00:00:00 2001 From: Jiaaming <2455951489@qq.com> Date: Mon, 5 Aug 2024 14:50:57 +0800 Subject: [PATCH 2/2] Refine error msg --- extension/src/server/GradleServer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extension/src/server/GradleServer.ts b/extension/src/server/GradleServer.ts index 3bc2675ae..432969815 100644 --- a/extension/src/server/GradleServer.ts +++ b/extension/src/server/GradleServer.ts @@ -41,7 +41,7 @@ export class GradleServer { private setLanguageServerPipePath(): void { this.languageServerPipePath = getRandomPipeName(); if (this.languageServerPipePath === "") { - this.logger.error("Failed to generate language server pipe path, language server will not start"); + this.logger.error("Gradle language server will not start due to pipe path generation failure"); } } @@ -55,7 +55,7 @@ export class GradleServer { if (isPrepared) { startBuildServer = true; } else { - this.logger.error("Failed to generate build server pipe path, build server will not start"); + this.logger.error("Gradle build server will not start due to pipe path generation failure"); } } this.bspProxy.setBuildServerStarted(startBuildServer);