pyright-for-pycharm icon indicating copy to clipboard operation
pyright-for-pycharm copied to clipboard

Is WSL supported on LSP mode?

Open tsunamilx opened this issue 6 months ago • 5 comments

I am using WSL (Ubuntu), and only command line mode is working for me, tried both LSP4IJ and Native LSP, neither of them is working.

For LSP4IJ, the server does not start, the error says "pyright-langserver is not a valid Win32 program". For Native LSP, the server starts, but it is not checking anything, no error/warn shown as I edit the code while command line mode correctly shows.

I checked the log, and noticed some difference from Ruff and Pyright for the same file. The logs:

RuffServerServerDescriptor@project: {"jsonrpc":"2.0","id":"19","result":[{"data":"file:///wsl$/Ubuntu/home/lixiao/project/utils/pdutil.py","kind":"source.fixAll.ruff","title":"Ruff: Fix all auto-fixable problems"},{"data":"file:///wsl$/Ubuntu/home/lixiao/project/utils/pdutil.py","kind":"source.organizeImports.ruff","title":"Ruff: Organize imports"}]}
PyrightServerDescriptor@project: {"jsonrpc":"2.0","id":"13","method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///home/lixiao/project/utils/pdutil.py"},"range":{"start":{"line":231,"character":0},"end":{"line":231,"character":0}},"context":{"diagnostics":[],"triggerKind":2}}}

The difference is the file path Ruff: "file:///wsl$/Ubuntu/home/lixiao/project/utils/pdutil.py" Pyright: "file:///home/lixiao/project/utils/pdutil.py"

So this might be the reason why it does not work because it is not sending WSL path?

In my opinion, this looks like the problem related to WSL, LSP4IJ thinks it is a Win32 program, and Native LSP does not send WSL path, not sure if the problem is from the LSP side or the plugin side, but as Ruff works fine, I am suspecting it might be the plugin that does not support WSL?

tsunamilx avatar Jun 10 '25 06:06 tsunamilx

That this plugin sends Linux paths instead of UNC paths is intentional. You are expected to have your Pyright executable, your project and your virtual environment all located in the same WSL distro for the plugin to work. The Pyright process is spawned on that distro.

(Take this advice with a grain of salt though; I haven't touched that part of the codebase in a long while.)

InSyncWithFoo avatar Jun 10 '25 07:06 InSyncWithFoo

See also #93, which is the most recently WSL-related issue.

InSyncWithFoo avatar Jun 10 '25 07:06 InSyncWithFoo

@InSyncWithFoo thanks for replying.

From what I understand, it's basically the same WSL path issue, but I dont seem to find the actual solution in #93 other than the fallback solution that is to use command line mode. My executable path and langserver path are all under the WSL path, e.g. "\wsl.localhost\Ubuntu\home\lixiao.local\share\virtualenvs\project\bin\pyright"

Is the command line mode only solution for WSL for now? I dont know what else I can do.

tsunamilx avatar Jun 10 '25 07:06 tsunamilx

Same issue here.

It does make sense that the pyright plugin would use linux paths if run within linux.

The question is, if it knows its being sent WSL paths, which it looks like it does, would it make sense to return as the same?

It seems that we are doing that conversion:

  • https://github.com/InSyncWithFoo/pyright-for-pycharm/issues/93#issuecomment-2513423038

Looking at this further, it looks like we know we have wsl via module.wslDistribution

Considering this, I think we could save our WSL prefix and hook into the outgoing diagnostics to append the prefix. If anyone has any thoughts, let me know. I haven't worked with this codebase yet, but I could probably make the change.

nonara avatar Sep 01 '25 22:09 nonara

@nonara Contributions are very much appreciated! If you submit a PR, I'll review it.

InSyncWithFoo avatar Sep 02 '25 07:09 InSyncWithFoo