vscode-ruff icon indicating copy to clipboard operation
vscode-ruff copied to clipboard

Does not work multiroot workspace with remote development

Open Real-Gecko opened this issue 11 months ago • 18 comments

Following #652 here's the problem: f I open multiroot workspace on remote server Ruff does not work, however if I just open folder(root folder where .code-workspace is) Ruff starts working. Setting this one does not help:

{
  "ruff.importStrategy": "useBundled"
}

Might also be related to #653

Real-Gecko avatar Dec 17 '24 04:12 Real-Gecko

Note: I've connected to new server where Ruff is not installed at all, and it's not in .venv

Real-Gecko avatar Dec 17 '24 04:12 Real-Gecko

Hmm interesting. Would you be able to share some logs with us? See the troubleshooting section for how you can enable logging

MichaReiser avatar Dec 24 '24 16:12 MichaReiser

Hmm interesting. Would you be able to share some logs with us? See the troubleshooting section for how you can enable logging

I've set "ruff.trace.server": "verbose" in my settings.json but the only thing I see in Ruff logs is:

2024-12-27 08:46:05.413 [info] Name: Ruff
2024-12-27 08:46:05.413 [info] Module: ruff
2024-12-27 08:46:05.413 [info] Python extension loading
2024-12-27 08:46:05.413 [info] Waiting for interpreter from python extension.
2024-12-27 08:46:05.413 [info] Python extension loaded
2024-12-27 08:46:05.413 [info] Using interpreter: /path/to/project/.venv/bin/python

Real-Gecko avatar Dec 27 '24 06:12 Real-Gecko

Hmm interesting. An older Ruff version had a bug where it got stuck after the using interpreter message but I assume you're using a recent version of the Ruff extension?

Can you try pinning the Ruff status in the VS code toolbar. Does it show Ruff (native), Ruff (ruff-lsp) or does it have a spinning icon next to it (which would suggest it got stuck during startup)?

MichaReiser avatar Dec 27 '24 17:12 MichaReiser

I seem to have this issue as well. Pinning Ruff leads to a spinning icon next to it.

I've found a workaround for now: select the interpreter at the workspace level. That seems to do the trick instead of doing it for a specific folder.

AndreasBackx avatar Dec 28 '24 20:12 AndreasBackx

I seem to have this issue as well. Pinning Ruff leads to a spinning icon next to it.

Thanks. That's interesting. It suggests that Ruff gets stuck during startup. @dhruvmanila do you have an idea why this is happening?

MichaReiser avatar Dec 28 '24 22:12 MichaReiser

I seem to have this issue as well. Pinning Ruff leads to a spinning icon next to it.

I've found a workaround for now: select the interpreter at the workspace level. That seems to do the trick instead of doing it for a specific folder.

Exactly same issue, constantly spinning icon next to Ruff Image

Real-Gecko avatar Dec 30 '24 07:12 Real-Gecko

Thanks. That's helpful because it means we can narrow it down to Ruff getting stuck during startup.

MichaReiser avatar Dec 30 '24 17:12 MichaReiser

I tried reproducing the bug using GitHub code spaces but ruff works as expected, even with multiple workspaces. Which is disappointing in this case.

Could someone open and share the output of the Output - Extension Host (Remote?) tab. You should see something like this if the Ruff extension fails to start with an exception

2024-12-31 13:37:36.100 [warning] Accessing a resource scoped configuration without providing a resource is not expected. To get the effective value for 'files.watcherExclude', provide the URI of a resource or 'null' for any resource.
2024-12-31 13:37:36.100 [warning] Accessing a resource scoped configuration without providing a resource is not expected. To get the effective value for 'files.watcherExclude', provide the URI of a resource or 'null' for any resource.
2024-12-31 13:37:36.998 [error] Error: Whoopos
	at startServer (/Users/micha/astral/ruff-vscode/dist/extension.js:21740:11)
	at async runServer (/Users/micha/astral/ruff-vscode/dist/extension.js:25610:24)
	at async kh.value (/Users/micha/astral/ruff-vscode/dist/extension.js:25622:9)

MichaReiser avatar Dec 31 '24 12:12 MichaReiser

I also encountered this issue. From the logs, it looks like it's using the python interpreter from one of the folders in my workspace, just not the one that I want it to use.

I tried doing Python: Select Interpreter > Select at workspace level but that seemed to have no effect.

One workaround is to explicitly set the interpreter in the workspace settings, e.g.:

  "ruff.interpreter": [
    "${workspaceFolder:desired-folder-name}/path/to/python"
  ]

chazmo03 avatar Jan 08 '25 16:01 chazmo03

@chazmo03 Apologies for the late reply, can you share a minimal directory structure which I can use to reproduce this issue?

From the logs, it looks like it's using the python interpreter from one of the folders in my workspace, just not the one that I want it to use.

For context, the extension will try to get the Python interpreter details from the Python extension if not provided via ruff.interpreter:

https://github.com/astral-sh/ruff-vscode/blob/b6a7b2d63639a66b9a9d4df2a40e16051fcf121e/src/common/python.ts#L49-L58

dhruvmanila avatar Jan 15 '25 04:01 dhruvmanila

Can confirm that setting this in my workspace config fixed the issue, even tho this was the interpreter being detected by ruff (according to logs) before applying this setting:

"ruff.interpreter": [
			"${workspaceFolder}/.venv/bin/python"
		]

kdkavanagh avatar Jan 16 '25 22:01 kdkavanagh

@kdkavanagh If you don't mind, I'd love to get the logs for the scenario where it's not working along with the directory structure and VS Code settings :)

dhruvmanila avatar Jan 17 '25 03:01 dhruvmanila

@dhruvmanila, I'm not doing anything special, just 3 folders - 1 with my main python project and 2 other non-python projects.

In the above getInterpreterDetails function, it looks like it would need the resource to be supplied so that it can identify which environment/workspace that file belongs to, but when that function is called from initializePython, no resource is supplied. Could that be causing the issue?

chazmo03 avatar Jan 17 '25 16:01 chazmo03

For me, a similar problem went away after I copied my vscode settings from my code workspace root into the workspace folder:

{
    "[python]": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "charliermarsh.ruff"
    }
}

as if the extension wasn't able to properly make sense of the root-level settings.

danieleds avatar Jan 21 '25 16:01 danieleds

I had the same problem, related to multi-root, and I believe it's related to the Python extension caching things in a bad way.

If you do Python: Clear Cache and Reload Window makes it work again for me.

rdbisme avatar Jan 30 '25 11:01 rdbisme

PS: this was impossible to debug using Troubleshooting because it was hanging before, apparently, it read my JSON. So I got no log level change or log file which I had configured. Maybe you want to make that to get resolved earlier.

rdbisme avatar Jan 30 '25 11:01 rdbisme

Hey everyone! I have an update on the issue: by analyzing Extnsion Host(Remote) logs I've noticed an error related to not being able to locate /usr/bin/python, I've checked on the server and only /usr/bin/python3 was available, so as I'm using ubuntu I've used apt install python-is-python3 which simply creates symlink /usr/bin/python -> /usr/bin/python3. And now ruff works as expected. The problem is that I tried to reproduce the issue by removing symlink and restarting vscode. But now everything just works, even without symlink, so I'm not sure how to check the exact message. The one thing for sure is that if /usr/bin/python is not present you'll get the error.

Real-Gecko avatar Oct 30 '25 09:10 Real-Gecko