georgewfraser / java-language-server

Java language server using the Java compiler API
MIT License
642 stars 126 forks source link

Couldn't start client Java Language Server #270

Open n1nja88888 opened 1 year ago

n1nja88888 commented 1 year ago

OS: Windows10 Version: 0.2.46

I just installed this extension in VS Code and then I ran into this error. Did I miss out on something? Are there any prerequisites before installing this extension?

n1nja88888 commented 1 year ago

The output as follows: Error: spawn UNKNOWN at ChildProcess.spawn (node:internal/child_process:441:11) at Object.spawn (node:child_process:752:9) at c:\Users\N1NJA88888.vscode\extensions\georgewfraser.vscode-javac-0.2.46\node_modules\vscode-languageclient\lib\main.js:357:40

grimly commented 1 year ago

Hello,

Some more information on this issue that I share :

The extension try to run %USERPROFILE%\.vscode\extensions\georgewfraser.vscode-javac-0.2.46\dist\lang_server_windows.sh

Of course, starting a shell script in Windows may only crash. I understand this is something about WSL. Here is the code to blame : https://github.com/georgewfraser/java-language-server/blob/master/lib/extension.ts#L327-L328

For an immediate fix, change the file %USERPROFILE%\.vscode\extensions\georgewfraser.vscode-javac-0.2.46\out\lib\extension.js at line 300+ :

  function platformSpecificLangServer() {
      switch (process.platform) {
          case 'win32':
-             return ['dist', 'lang_server_windows.sh'];
+             return ['dist', 'lang_server_windows.cmd'];
          case 'darwin':
              return ['dist', 'lang_server_mac.sh'];
          case 'linux':
              return ['dist', 'lang_server_linux.sh'];
      }
      throw `unsupported platform: ${process.platform}`;
  }

Once that changed. I'm running into an other issue, Java 17 is not enough :

java.lang.UnsupportedClassVersionError: org/javacs/Main has been compiled by a more recent version of the Java Runtime (class file version 62.0), this version of the Java Runtime only recognizes class file versions up to 61.0

It requires at least Java 18. This is unfortunate at this very moment but a new LTS is comming soon so I won't mind for now. The current documentation states Java 13

If someone has the knowledge to detect if the user is either using plain windows or WSL, your input on this platformSpecificLangServer function is most welcome.