java-language-server icon indicating copy to clipboard operation
java-language-server copied to clipboard

A UNKNOWN spawn Error lead to Java Language Server Client failure when start a Java Language Service at Windows Platform

Open GitPopcorn opened this issue 4 years ago • 1 comments

I'm sorry I cannot record the very detail of this issue. I got only a few screenshots to describe it. So it's fine to close this issue if it cannnot be reproduced.

The error in VSCode window log. Snipaste_2020-08-20_09-26-15

The arguments used in spawn() method. Snipaste_2020-08-20_09-26-00

Try to rerun the command in REPL of NodeJS Snipaste_2020-08-20_09-27-59

In fact, I do keep a sh.exe/bash.exe in my PATH variables and can run "sh c:\Users\QQ370\.vscode\extensions\georgewfraser.vscode-javac-0.2.33\dist\lang_server_windows.sh" immediately in terminal or event without the "sh " prefix, but I'm not familiar with NodeJS so I don't know if it's necessary to adding the "shell = true" in the options of spawn.

By the way, I have check the variable chain of "options" used in the vscode-languageclient/lib/main.js: "arg2/arg3" -> "serverOptions" -> "_serverOptions" -> "server" -> "json" -> "node" -> "options" -> "execOptions" It did not do anything about the "shell" options, so I'm not clear whether you or the vscode-languageserver-node group should be responsible for this issue.

GitPopcorn avatar Aug 20 '20 01:08 GitPopcorn

Hey dudes, I just find a new way to avoid this issue in Windows platform: Change the command from "xx/xx/xx.sh" to "cmd xx/xx/xx.sh";

At first I try to add "shell" options to the spawn operation, but I find it will lead to a visible shell window which remains among the language service running. The I thought to change the command structure and try it in NodeJS, finnaly I got this way to solve this issue, behind is the code.

The code in "%USERPROFILE%\.vscode\extensions\georgewfraser.vscode-javac-0.2.33\node_modules\vscode-languageclient\lib\main.js" from Line 352:

            else if (Executable.is(json) && json.command) {
                let command = json;
                let args = command.args || [];
                let options = Object.assign({}, command.options);
                options.cwd = options.cwd || serverWorkingDir;
                // TEST Number [2020-08-21 21:54:16] Try to solve the problem of "Couldn't start client Java Language Server - Error: spawn UNKNOWN"
                if (command.command.endsWith('sh') && process.platform.includes('win')) {
                    // CONDITION Number If try to run Shell script in Windows Enviroment, add additional options to the command.
                    // options.shell = true;

                    // CONDITION Number If try to run Shell script in Windows Enviroment, change the structure of command.
                    args.splice(0, 0, command.command);
                    command.command = "cmd";

                }
                let serverProcess = cp.spawn(command.command, args, options);
                if (!serverProcess || !serverProcess.pid) {
                    return Promise.reject(`Launching server using command ${command.command} failed.`);
                }
                serverProcess.stderr.on('data', data => this.outputChannel.append(Is.string(data) ? data : data.toString(encoding)));
                this._serverProcess = serverProcess;
                this._isDetached = !!options.detached;
                return Promise.resolve({ reader: new vscode_languageserver_protocol_1.StreamMessageReader(serverProcess.stdout), writer: new vscode_languageserver_protocol_1.StreamMessageWriter(serverProcess.stdin) });
            }
            return Promise.reject(new Error(`Unsupported server configuration ` + JSON.stringify(server, null, 4)));

Besides my version of NodeJS is V12.18.1, I don't know if it matters, I'll test later with a NodeJS of V14.

GitPopcorn avatar Aug 26 '20 02:08 GitPopcorn