astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.04k stars 52 forks source link

ruff crash in remote developement (ssh) in VSCode #578

Open ingempo opened 1 month ago

ingempo commented 1 month ago

System info:

Host/Remote OS Name: Microsoft Windows 10 Enterprise Host/Remote OS Version: 10.0.19044 N/A Build 19044 VSCode version: 1.92.1 (user setup) Ruff version: 0.5.7 Python version: 3.9.13 Ruff log: ruff.log

settings.json:

"[python]":{
          "editor.defaultFormatter":"charliermarsh.ruff",
          "editor.wordBasedSuggestions":"matchingDocuments",
          "editor.formatOnType":true,
          "editor.formatOnSave":true,
          "editor.formatOnPaste":true,
          "editor.codeActionsOnSave":{
              "source.fixAll":"never",
              "source.organizeImports":"always"
          }
      },
    "python.analysis.typeCheckingMode":"basic",
    "python.analysis.completeFunctionParens":true, 
    "python.analysis.inlayHints.variableTypes":true,
    "python.analysis.inlayHints.functionReturnTypes":true,
    "python.analysis.inlayHints.callArgumentNames":"off",
    "python.analysis.inlayHints.pytestParameters":true,
    "python.analysis.enablePytestSupport":true,

Notes:

dhruvmanila commented 1 month ago

Hmm, this is weird. The logs says:

2024-08-08 17:42:52.601 [info] ruff failed
  Cause: Failed to convert workspace URL to file path: file:///work/hardware-qualification

But, the conversion succeeds:

Ok(
    Url {
        scheme: "file",
        cannot_be_a_base: false,
        username: "",
        password: None,
        host: None,
        port: None,
        path: "/work/hardware-qualification",
        query: None,
        fragment: None,
    },
)
dhruvmanila commented 1 month ago

ruff works well on host and remote machines when vscode is launched locally.

Does this mean that this failure only occurs when VS Code is launched in the remote machine? How does that work?

MichaReiser commented 1 month ago

@ingempo are you using WSL? I noticed that the log shows 2024-08-08 17:42:52.451 [info] Using interpreter: \work\hardware-qualification\.venv\Scripts\python.exe

Edit: Right, you're remoting

ingempo commented 1 month ago

ruff works well on host and remote machines when vscode is launched locally.

Does this mean that this failure only occurs when VS Code is launched in the remote machine? How does that work?

Exactly ! ruff works well when I use vscode locally in the host (my own laptop) and remote (RDC) I don't know what happend.

ingempo commented 1 month ago

@ingempo are you using WSL? I noticed that the log shows 2024-08-08 17:42:52.451 [info] Using interpreter: \work\hardware-qualification\.venv\Scripts\python.exe

Edit: Right, you're remoting

No, I'm not using WSL. Host and remote are physical windows machines. My project comes with its own python virtual env. vscode uses this as default interpreter.

ingempo commented 1 month ago

Hmm, this is weird. The logs says:

2024-08-08 17:42:52.601 [info] ruff failed
  Cause: Failed to convert workspace URL to file path: file:///work/hardware-qualification

But, the conversion succeeds:

Ok(
    Url {
        scheme: "file",
        cannot_be_a_base: false,
        username: "",
        password: None,
        host: None,
        port: None,
        path: "/work/hardware-qualification",
        query: None,
        fragment: None,
    },
)

Maybe the path has an extra slash at the beginning? It is weird for me to see a path with 3 slashes?

MichaReiser commented 1 month ago

@dhruvmanila I could try to repro the conversion on windows if you want. The to_file_path method has some conditional compiled code in it.

dhruvmanila commented 1 month ago

@MichaReiser Yeah, that would be useful, thanks.

dhruvmanila commented 1 month ago

Maybe the path has an extra slash at the beginning? It is weird for me to see a path with 3 slashes?

No, the path is correct. The two slashes are part of the scheme, kind of like https://..., so file:// and then the path /work/hardware-qualification.

dhruvmanila commented 1 month ago

@ingempo Can you try setting the following setting and see if the problem persists?

{
    "ruff.nativeServer": "off"
}

Currently, as per the logs, the extension is automatically using the native server. I'm guessing that ruff-lsp shouldn't be affected by this but it would be useful to confirm that.

ingempo commented 1 month ago

Hi @dhruvmanila, sorry for delay.

Not success with:

{
    "ruff.nativeServer": "off"
}

Current ruff log:

2024-08-12 16:35:50.858 [info] Name: Ruff
2024-08-12 16:35:50.858 [info] Module: ruff
2024-08-12 16:35:50.859 [debug] Full Server Info: {"name":"Ruff","module":"ruff"}
2024-08-12 16:35:50.859 [info] Python extension loading
2024-08-12 16:35:50.859 [info] Waiting for interpreter from python extension.
2024-08-12 16:35:50.859 [info] Python extension loaded
2024-08-12 16:35:50.859 [info] Using interpreter: \work\hardware-qualification\.venv\Scripts\python.exe
2024-08-12 16:35:50.859 [info] Server run command: \work\hardware-qualification\.venv\Scripts\python.exe c:\Users\opalrtlinux\.vscode-server\extensions\charliermarsh.ruff-2024.38.0-win32-x64\bundled\tool\server.py
2024-08-12 16:35:50.859 [info] Server: Start requested.
2024-08-12 16:35:50.860 [debug] Server State: Starting
2024-08-12 16:35:50.860 [debug] Server State: Stopped
2024-08-12 16:35:50.860 [info] [Error - 4:35:49 p.m.] Ruff client: couldn't create connection to server.
2024-08-12 16:35:50.860 [info] Launching server using command \work\hardware-qualification\.venv\Scripts\python.exe failed. Error: spawn \work\hardware-qualification\.venv\Scripts\python.exe ENOENT
2024-08-12 16:35:50.860 [error] Server: Start failed: Launching server using command \work\hardware-qualification\.venv\Scripts\python.exe failed. Error: spawn \work\hardware-qualification\.venv\Scripts\python.exe ENOENT

python interprete is there:

Microsoft Windows [Version 10.0.19044.4529]
(c) Microsoft Corporation. All rights reserved.

(.venv) opalrtlinux@DEVOPS-WIP-01 C:\work\hardware-qualification>where python
C:\work\hardware-qualification\.venv\Scripts\python.exe

(.venv) opalrtlinux@DEVOPS-WIP-01 C:\work\hardware-qualification>python --version 
Python 3.9.13
dhruvmanila commented 1 month ago

The interpreter path doesn't look correct as it's starting from \work\... instead of c:\work\... (?). Do you have the ruff.interpreter set anywhere in your VS Code config (global, workspace, per-folder)?

I noticed that you're using the VS Code server. So, the server is hosted on a Windows machine and are you accessing it via a local VS Code instance? How does SSH work here? I'm asking because the docs mentions that this doesn't require SSH connection.

ingempo commented 1 month ago

Hi !

I don't set ruff.interpreter in VS Code settings. And my setup is like you say, in other words: remote developement using ssh (https://code.visualstudio.com/docs/remote/ssh)

I don't get your question: How does SSH works here? I presume that in the link I gave you is the description of how SSH works for remote development setup.