Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Biome plugin not working with WSL #49

Open
niklas-e opened this issue Apr 10, 2024 · 7 comments
Open

Biome plugin not working with WSL #49

niklas-e opened this issue Apr 10, 2024 · 7 comments

Comments

@niklas-e
Copy link

niklas-e commented Apr 10, 2024

I tried to use the plugin with a project in Windows Subsystem for Linux. I couldn't get it to work and tried to gather some relevant log entries from the IDEA logs.

First I tried with Automatic Biome configuration. The plugin seemingly loads fine, no errors. However the formatter hangs on save and I got this in the logs:

2024-04-10 19:17:24,713 [ 777798] SEVERE - #com.github.biomejs.intellijbiome.actions.BiomeCheckRunner - Failed to run Biome check with (format, safefixes) for file App.jsx - Timeout exceeded
java.lang.Throwable: Failed to run Biome check with (format, safefixes) for file App.jsx - Timeout exceeded
        at com.intellij.openapi.diagnostic.Logger.error(Logger.java:376)
        at com.github.biomejs.intellijbiome.actions.BiomeCheckRunner.applyChanges(BiomeCheckRunner.kt:91)
        at com.github.biomejs.intellijbiome.actions.BiomeCheckRunner.access$applyChanges(BiomeCheckRunner.kt:20)
        at com.github.biomejs.intellijbiome.actions.BiomeCheckRunner$formatDocuments$1$1.run(BiomeCheckRunner.kt:58)
        at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:477)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:133)
--
        at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
        at java.base/java.lang.Thread.run(Thread.java:840)

Then I tried with Manual Biome configuration pointing executable and biome.json to files inside WSL. The plugin immediately indicates the language server is terminated (screenshot below). In addition when saving any file the log contains entries about invalid path (see below).

image

2024-04-10 19:25:52,261 [1285346] SEVERE - #c.i.o.p.Task - Cannot run program "\\wsl.localhost\Ubuntu-22.04\home\niklas\code\my-project\node_modules\.bin\biome" (in directory "\\wsl.localhost\Ubuntu-22.04\home\niklas\code\my-project"): CreateProcess error=3, The system cannot find the path specified
com.intellij.execution.process.ProcessNotCreatedException: Cannot run program "\\wsl.localhost\Ubuntu-22.04\home\niklas\code\my-project\node_modules\.bin\biome" (in directory "\\wsl.localhost\Ubuntu-22.04\home\niklas\code\my-project"): CreateProcess error=3, The system cannot find the path specified
        at com.intellij.execution.configurations.GeneralCommandLine.createProcess(GeneralCommandLine.java:366)
        at com.intellij.execution.process.OSProcessHandler.startProcess(OSProcessHandler.java:86)
        at com.intellij.execution.process.OSProcessHandler.<init>(OSProcessHandler.java:46)
        at com.intellij.execution.process.CapturingProcessHandler.<init>(CapturingProcessHandler.java:20)
        at com.github.biomejs.intellijbiome.extensions.CommandLineExtKt.runProcessFuture(CommandLineExt.kt:26)
        at com.github.biomejs.intellijbiome.BiomeStdinRunner.check(BiomeStdinRunner.kt:34)
        at com.github.biomejs.intellijbiome.actions.BiomeCheckRunner$formatDocuments$1$1.run(BiomeCheckRunner.kt:55)
        at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:477)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:133)
--
        at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
        at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.io.IOException: Cannot run program "\\wsl.localhost\Ubuntu-22.04\home\niklas\code\my-project\node_modules\.bin\biome" (in directory "\\wsl.localhost\Ubuntu-22.04\home\niklas\code\my-project"): CreateProcess error=3, The system cannot find the path specified
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
--
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
        ... 34 more

Probably requires some additional handling to get it working with WSL, but I guess it should be doable since IDEA works nicely with WSL.

On a side note: would be worth it to add some error handling too, because especially with the automatic configuration there's no errors so the plugin just shows as not working or buggy for the user.


Environment information:

IntelliJ IDEA 2024.1 (Ultimate Edition)
Biome plugin v1.0.0
Biome 1.6.4

@martinbiard
Copy link

martinbiard commented Apr 16, 2024

I've got somewhat of the same issue here. My situation is a little different as I'm running my server inside docker instead of inside WSL, but the issue is very likely to be the same thing since I expect in both cases, IntelliJ is being run as client/server.

The LSP server starts then exits immediately with error code 137 as can be seen in logs below.

2024-04-16 15:16:35,479 [ 476993]   INFO - #c.i.p.l.a.LspServerDescriptor - LspServerDescriptor@workspace: starting LSP server: /usr/bin/node [/workspace/node_modules/@biomejs/biome/bin/biome, lsp-proxy]
2024-04-16 15:16:35,482 [ 476996]   INFO - #c.i.p.l.i.LspServerImpl - LspServerDescriptor@workspace(Initializing;0): LSP server process started: /usr/bin/node /workspace/node_modules/@biomejs/biome/bin/biome lsp-proxy
2024-04-16 15:16:35,484 [ 476998]   INFO - #c.i.p.l.i.LspServerImpl - LspServerDescriptor@workspace(ShutdownNormally;0): LSP server process terminated, exit code = 137, command line: /usr/bin/node /workspace/node_modules/@biomejs/biome/bin/biome lsp-proxy
2024-04-16 15:16:35,506 [ 477020]   INFO - #c.i.p.l.i.LspServerImpl - LspServerDescriptor@workspace(Running;0): LSP server initialized, name = biome_lsp, version = 1.7.0
2024-04-16 15:16:35,508 [ 477022]   INFO - #c.i.p.l.i.LspServerImpl - LspServerDescriptor@workspace(Running;3): window/logMessage: Server initialized with PID: 90828
2024-04-16 15:17:07,104 [ 508618]   INFO - #c.j.r.d.BackendDiagnosticsHost - A CWM client requested logs

I've read that exit code 137 can often mean running out of memory, but in my case everything looks perfectly fine from inside my docker container:

top - 15:47:37 up 9 days, 15:12,  0 user,  load average: 0.22, 0.15, 0.18
Tasks:  16 total,   1 running,  15 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.5 us,  0.3 sy,  0.0 ni, 99.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st 
MiB Mem :  15900.5 total,   5071.4 free,   3584.1 used,   7621.4 buff/cache     
MiB Swap:   4096.0 total,   4085.3 free,     10.7 used.  12316.3 avail Mem

I'm not sure how to test if it's actually working, but when I run the command manually, it seems to be working, waiting for input and not exiting, so the lsp-proxy just won't stay up when running from the IDE.

/usr/bin/node /workspace/node_modules/@biomejs/biome/bin/biome lsp-proxy

IntelliJ IDEA 2024.1 (Ultimate Edition)
Biome plugin v1.0.2
Biome 1.7.0

@martinbiard
Copy link

I just noticed while running ps -aux that the lsp-proxy is actually running even though IntelliJ reports it as stopped.

@Richard87
Copy link

I think I have the same issue as well at #83 (comment)

I think a good fix would be not to rely on the installed biome binary, and use one from the host system. Then we could execute biome.exe, and the windows file paths would work fine?

I added this to Biome executable, and everything seems to work fine:

C:/Users/richard.hagen/AppData/Roaming/npm/biome.cmd

@niklas-e
Copy link
Author

Using the binary from host is definitely not a good fix, because most users will not have the binary on their host machine if they have their projects inside WSL. At least that is the case in all of my projects where Biome is used. In addition there would be version mismatches.

@Richard87
Copy link

I totally agree, but I think/feel the easier fix would be for the plugin to download the binary instead of translating the filepaths... (but I'm sure the maintainers have a better idea :D)

@niklas-e
Copy link
Author

niklas-e commented Sep 14, 2024

Downloading won't work in all environments (e.g. if you don't have access to internet).

I researched a bit and found something that could be a viable solution. I played a bit with my AI friend since I don't want to setup intellij idea plugin development environment atm. Based on testing wslpath on my machine, this seems plausible to me, but sorry if this is blatantly wrong... also I wouldn't be surprised if there's built-in utils to handle these things inside intellij plugins 😅

  1. Determine if we are currently in WSL
public boolean isRunningInWSL() {
    String wslDistroName = System.getenv("WSL_DISTRO_NAME");
    return wslDistroName != null;
}
  1. wslpath tool (can convert paths from/to wsl paths)

Testable in e.g. PowerShell:

wsl wslpath -u C:\\path\\to\\file
# -> outputs /mnt/c/path/to/file
wsl wslpath -w /mnt/c/path/to/file
# -> output: C:\path\to\file
private String convertWindowsPathToWSL(String windowsPath) {
        try {
            Process process = new ProcessBuilder("wsl", "wslpath", "-u", windowsPath).start();
            process.waitFor();
            String wslPath = new String(process.getInputStream().readAllBytes()).trim();
            return wslPath;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

private String convertWSLPathToWindows(String wslPath) {
        try {
            Process process = new ProcessBuilder("wsl", "wslpath", "-w", wslPath).start();
            process.waitFor();
            String windowsPath = new String(process.getInputStream().readAllBytes()).trim();
            return windowsPath;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

@Richard87
Copy link

Many plugins are installing their own binary when required, and I think its a more foolproof option without trying to parse the path. Then everything would run in the same environment (editor / biome) which solves a few things.

But what fix does the maintainers prefer? would they accept a PR for either of these options?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants