scalameta / metals-vscode

Visual Studio Code extension for Metals
https://marketplace.visualstudio.com/items?itemName=scalameta.metals#overview
Apache License 2.0
300 stars 76 forks source link

Can't start Metals server with JDK with cyrillic characters in the path #1509

Open divijan opened 5 months ago

divijan commented 5 months ago

Unable to start Metals extension with cyrillic characters in path under Windows Cannot find java executable in path with cyrillic characters in it.

Metals Extension output:

Metals version: 1.3.1
Using coursier located at C:\Users\до\.metals\cs.exe //here my two-character cyrillic username is displayed correctly, I just changed it for security reasons
C:\Program Files\Eclipse Adoptium\jdk-8.0.412.8-hotspot\bin\java -version:
openjdk version "1.8.0_412"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_412-b08)
OpenJDK 64-Bit Server VM (Temurin)(build 25.412-b08, mixed mode)
Found java executable under C:\Program Files\Eclipse Adoptium\jdk-8.0.412.8-hotspot\bin\java.exe that resolves to C:\Program Files\Eclipse Adoptium\jdk-8.0.412.8-hotspot\bin\java.exe
C:\Program Files\Eclipse Adoptium\jdk-8.0.412.8-hotspot\bin\java -version:
openjdk version "1.8.0_412"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_412-b08
C:\Program Files\Eclipse Adoptium\jdk-8.0.412.8-hotspot\bin\java -version:
)
OpenJDK 64-Bit Server VM (Temurin)(build 25.412-b08, mixed mode)
No installed java with version 17 found. Will fetch one using coursier.
Coursier: openjdk version "17" 2021-09-14
OpenJDK Runtime Environment Temurin-17+35 (build 17+35)
OpenJDK 64-Bit Server VM Temurin-17+35 (build 17+35, mixed mode, sharing)
Using Java Home: C:\Users\??\AppData\Local\Coursier\cache\arc\https\github.com\adoptium\temurin17-binaries\releases\download\jdk-17%252B35\OpenJDK17-jdk_x64_windows_hotspot_17_35.zip\jdk-17+35 //first time I see ?? instead of cyrillic characters
[Error - 5:47:06 PM] Metals client: couldn't create connection to server.
Launching server using command C:\Users\??\AppData\Local\Coursier\cache\arc\https\github.com\adoptium\temurin17-binaries\releases\download\jdk-17%252B35\OpenJDK17-jdk_x64_windows_hotspot_17_35.zip\jdk-17+35\bin\java failed. Error: spawn C:\Users\??\AppData\Local\Coursier\cache\arc\https\github.com\adoptium\temurin17-binaries\releases\download\jdk-17%252B35\OpenJDK17-jdk_x64_windows_hotspot_17_35.zip\jdk-17+35\bin\java ENOENT

To Reproduce:

  1. Do not have the necessary version of Java installed manually
  2. Go to 'File/Open Folder' and choose any folder with sbt project
  3. Click on 'Go to output' in the error alert with title 'Metals client: couldn't create connection to server.' at the right bottom corner of the VSCode window
  4. See the error message

Expected behavior

VS Code should be able to start the server because the java executable is there, the launcher can't seem to understand the cyrillic characters in the path.

Installation:

Additional context

After I have 'officially' installed JDK 17 under Program Files, the problem has shifted its shape to this:

Metals version: 1.3.1
Using coursier located at C:\Users\до\.metals\cs.exe //again, obfuscated the cyrillic username
C:\Program Files\Eclipse Adoptium\jdk-17.0.11.9-hotspot\bin\java -version:
openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment Temurin-17.0.11+9 (build 17.0.11+9)
OpenJDK 64-Bit Server VM Temurin-17.0.11+9 (build 17.0.11+9, mixed mode, sharing)
Using Java Home: C:\Program Files\Eclipse Adoptium\jdk-17.0.11.9-hotspot\
Error: Could not find or load main class scala.meta.metals.Main
Caused by: java.lang.ClassNotFoundException: scala.meta.metals.Main
[Error - 6:05:42 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 6:05:42 PM] Connection to server got closed. Server will restart.
true
[Error - 6:05:42 PM] Metals client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
Error: Could not find or load main class scala.meta.metals.Main
Caused by: java.lang.ClassNotFoundException: scala.meta.metals.Main
[Error - 6:05:43 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 6:05:43 PM] Connection to server got closed. Server will restart.
true
[Error - 6:05:43 PM] Metals client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
Could not launch Metals Language Server:
Pending response rejected since connection got disposed
Release notes was not shown: not showing release notes since they've already been seen for your current version
Error: Could not find or load main class scala.meta.metals.Main
Caused by: java.lang.ClassNotFoundException: scala.meta.metals.Main
[Error - 6:05:43 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 6:05:43 PM] Connection to server got closed. Server will restart.
true
[Error - 6:05:43 PM] Metals client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 6:05:43 PM] Restarting server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
Error: Could not find or load main class scala.meta.metals.Main
Caused by: java.lang.ClassNotFoundException: scala.meta.metals.Main
[Error - 6:05:43 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 6:05:43 PM] Connection to server got closed. Server will restart.
true
[Error - 6:05:43 PM] Metals client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 6:05:43 PM] Restarting server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
Error: Could not find or load main class scala.meta.metals.Main
Caused by: java.lang.ClassNotFoundException: scala.meta.metals.Main
[Error - 6:05:44 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 6:05:44 PM] The Metals server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 6:05:44 PM] Metals client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 6:05:44 PM] Restarting server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 

I found a similar problem described here. It is claimed to be fixed, but apparently not for all cases.

Search terms

Launching server using command ... failed., Error: Spawn ... ENOENT, cyrillic

tgodzik commented 5 months ago

Thanks for reporting! I might have a potential fix in https://github.com/scalameta/metals-vscode/pull/1510 though we had some issues with adding properties to native image before. Will need to confirm.

tgodzik commented 5 months ago

Looks like we couldn't add the java properties automatically since there seems to be a bug with coursier native image in Windows. Could you try adding JAVA_OPTS variable with "-Dfile.encoding=UTF-8" set? Let's see if that helps.

The alternative is to use old jar launcher when this happens.

divijan commented 5 months ago

I've set this variable through control panel and it didn't help. Tried option with and without quotes. When I install Java 17 as a normal Windows package, I get the error described in https://github.com/scalameta/metals-vscode/issues/366. Is it caused by the same glitch in coursier?

tgodzik commented 5 months ago

It's an issue with encoding, if we set it it should work correctly, but there seems to be an issue here with setting it. I am doing a workaround in the PR linked here.

divijan commented 2 months ago

Updated to metals 1.3.5 and metals-vscode 1.39.0. With or without Java 17 installed, the error messages are the same, corresponding to what I wrote above. Seems to me if you are a developer, writing your username in cyrillic characters in Windows is a bad idea. Had something else fail because of this yesterday.

tgodzik commented 2 months ago

Exactly the same? I hoped that the workaround would help, but then I will need to reproduce it locally on a windows machine :thinking:

divijan commented 2 months ago

Pretty much. With Java 17 not installed, exactly the same save the versions, and with Java installed, very little difference. Do you want me to produce the actual output?