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

Loading spinner stuck - ruff does nothing

Open chrisk314 opened this issue 1 year ago • 7 comments

Recently Ruff stopped performing any code actions for my python files and the extension state icon remains spinning indefinitely (see screenshot below). This issue is similar to #609 in appearance in the VS Code UI, but different in that there appears to be no communication with the ruff server. image

This started happening a couple of weeks ago without any changes to my vs code settings. I'm on auto update, so I guess an update caused this. I've tried with ruff.nativeServer set to on, off, and auto. This is all I get in the ruff logs (verbose logging enabled). Seeing this with all my environments. I've tried uninstalling the extension and reinstalling.

2024-09-19 20:57:24.113 [info] Name: Ruff
2024-09-19 20:57:24.113 [info] Module: ruff
2024-09-19 20:57:24.113 [info] Python extension loading
2024-09-19 20:57:24.113 [info] Waiting for interpreter from python extension.
2024-09-19 20:57:24.574 [info] Python extension loaded
2024-09-19 20:57:24.900 [info] Using interpreter: /home/csk/.pyenv/versions/plugboard-3.12/bin/python

User VS Code settings file Ruff config

{
    "ruff.nativeServer": "auto",
    "ruff.trace.server": "verbose",
}

Project VS Code settings file (.vscode/settings.json)

{
    "python.defaultInterpreterPath": "/home/csk/.pyenv/versions/plugboard-3.12/bin/python3.12",
    "python.envFile": "${workspaceFolder}/.env",
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
    "python.testing.autoTestDiscoverOnSaveEnabled": true,
    "python.testing.pytestArgs": [
        "-rs", "tests/"
    ],
    "editor.formatOnSave": false,
    "[python]": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.codeActionsOnSave": {
            "source.organizeImports": "explicit",
            "source.fixAll": "explicit"
        }
    },
    "mypy.configFile": "pyproject.toml",
    "mypy.targets": ["./plugboard", "./tests"],
    "mypy.runUsingActiveInterpreter": true,
}

Pyproject Ruff settings (pyproject.toml)

[tool.ruff]  # Code formatting and linting
line-length = 100
src = ["plugboard", "tests"]
extend-exclude = ["__pycache__"]
output-format = "grouped"

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.ruff.lint]
select = ["D", "E", "F", "I", "W"]
ignore = ["D105", "D107", "D401", "E203", "E226", "E24", "E731", "E741", "F541", "F821", "W605"]
exclude = ["docs/*"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.isort]
known-first-party = ["plugboard"]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
no-lines-before = ["local-folder"]
force-sort-within-sections = true
combine-as-imports = true
split-on-trailing-comma = true
relative-imports-order = "furthest-to-closest"
lines-after-imports = 2

My env:

  • VS Code v1.94.0 Insider
  • Ruff VS Code extension v2024.48.0
  • Windows 11
  • WSL2 with Ubuntu 24.04
  • Python 3.12.6 installed in pyenv
  • Python virtualenv installed with pyenv-virtualenv
  • Ruff v0.5.7 installed in venv (working correctly on CLI)

This problem is not limited to pyenv virtualenvs. I'm having the same issue with all VS Code projects some of which use virtualenvs created with the system python using python -m venv .venv etc.

chrisk314 avatar Sep 20 '24 10:09 chrisk314

Thanks for opening a new issue.

Looking into it. I believe the extension gets as far as startServer because that's the only path where we enable the spinner. But it doesn't make it as far as logging the startServer message...

https://github.com/astral-sh/ruff-vscode/blob/69a99f65afe4c400259910128b976137be45ad89/src/common/server.ts#L425-L441

I suspect it fails somewhere before createServer completes because we don't see the server kind in the status bar.

https://github.com/astral-sh/ruff-vscode/blob/69a99f65afe4c400259910128b976137be45ad89/src/common/server.ts#L394-L413

Just wondering because we had something similar in the past. Is there a message pop up showing up? If so, could you try dismissing it?

If not, could you try setting "ruff.nativeServer": "on", for debug purposes. Just in case it's a problem with the new native server but something that works with the old python based LSP.

MichaReiser avatar Sep 20 '24 12:09 MichaReiser

There is no message popping up related to Ruff. I tried setting "ruff.nativeServer": "on" but the Ruff output is just the same as before. Btw my VS Code just auto-updated Ruff and the version is now v2024.50.0. Problem persists.

chrisk314 avatar Sep 20 '24 13:09 chrisk314

I don't know what the problem is but I noticed that we aren't correctly logging errors if the extension fails to handle some request. I'll put up a PR improving logging and that should hopefully help us to narrow this down. Sorry that you're running into this.

MichaReiser avatar Sep 20 '24 14:09 MichaReiser

Maybe we can get the logs sooner. Do you see any error messages in the Output - Extension Host panel?

It should look like this (I intentionally introduced a bug to demonstrate this):

2024-09-20 16:43:52.542 [warning] [charliermarsh.ruff] Accessing a window scoped configuration for a resource is not expected. To associate 'ruff.showSyntaxErrors' to a resource, define its scope to 'resource' in configuration contributions in 'package.json'.
2024-09-20 16:43:53.546 [error] ReferenceError: setings is not defined
	at resolveNativeServerSetting (/home/micha/astral/ruff-vscode/dist/extension.js:21676:13)
	at createServer (/home/micha/astral/ruff-vscode/dist/extension.js:21727:51)
	at startServer (/home/micha/astral/ruff-vscode/dist/extension.js:21741:29)
	at async runServer (/home/micha/astral/ruff-vscode/dist/extension.js:25609:24)
	at async /home/micha/astral/ruff-vscode/dist/extension.js:25625:13

MichaReiser avatar Sep 20 '24 14:09 MichaReiser

OK I believe I have found and fixed the root cause by observing the Extension Host (Remote) output as you suggested. I noticed some error messages related to misconfigured python interpreter paths like those shown below (some info redacted). Recently I did a bit of cleanup of my drive, removing many old, no longer required virtualenvs. I still have the code for a few of the affected projects in my VS Code workspace for reference, but I'm not actively developing them, hence they don't need working python envs.

2024-09-20 15:56:08.862 [error] Error: Failed to resolve env "/home/csk/src/org/an-org/a-project/.venv-dev/bin/python"
    at ae (/home/csk/.vscode-server-insiders/extensions/ms-python.python-2024.14.1-linux-x64/out/client/extension.js:2:2041224)
    at oe (/home/csk/.vscode-server-insiders/extensions/ms-python.python-2024.14.1-linux-x64/out/client/extension.js:2:2039184)
    at Immediate.<anonymous> (/home/csk/.vscode-server-insiders/extensions/ms-python.python-2024.14.1-linux-x64/out/client/extension.js:2:2035478)
    at processImmediate (node:internal/timers:478:21)

After removing the problematic projects from VS Code the Ruff extension started working correctly again. Adding these problematic projects back into VS Code causes the Ruff extension to stop working once again. Perhaps this could be a useful test case.

For me the problem is resolved. I'll leave it up to you to either close this now, or keep it open to address the underlying issue if that makes sense. It's worth noting that other VS Code python extensions such as Mypy do continue to function correctly in the presence of these misconfigured python envs, so it feels like an issue with the Ruff extension, though I'm not knowledgable enough to make that determination.

Thanks for all your help @MichaReiser. I was surviving with my ruff pre-commit hooks but having the extension working again is great.

chrisk314 avatar Sep 20 '24 15:09 chrisk314

Thanks. That's helpful. Yeah I think we can improve the handling of errors or being more resilient against misconfigured interpreters. I'll mark this as an improvement.

MichaReiser avatar Sep 20 '24 15:09 MichaReiser

I am also seeing the stuck spinner. With the following error message in the Extension host Output:

2024-09-20 15:51:45.586 [error] Error: spawn UNKNOWN
	at ChildProcess.spawn (node:internal/child_process:421:11)
	at spawn (node:child_process:800:9)
	at execFile (node:child_process:352:17)
	at t.<computed> (node:electron/js2c/node_init:2:2610)
	at c:\Users\lonni\.vscode\extensions\charliermarsh.ruff-2024.50.0-win32-x64\dist\extension.js:1:51373
	at new Promise (<anonymous>)
	at S (c:\Users\lonni\.vscode\extensions\charliermarsh.ruff-2024.50.0-win32-x64\dist\extension.js:1:51338)
	at C (c:\Users\lonni\.vscode\extensions\charliermarsh.ruff-2024.50.0-win32-x64\dist\extension.js:1:51485)
	at c:\Users\lonni\.vscode\extensions\charliermarsh.ruff-2024.50.0-win32-x64\dist\extension.js:1:54135
	at async w (c:\Users\lonni\.vscode\extensions\charliermarsh.ruff-2024.50.0-win32-x64\dist\extension.js:1:53145)
	at async t.startServer (c:\Users\lonni\.vscode\extensions\charliermarsh.ruff-2024.50.0-win32-x64\dist\extension.js:1:56839)
	at async S (c:\Users\lonni\.vscode\extensions\charliermarsh.ruff-2024.50.0-win32-x64\dist\extension.js:1:397112)
	at async i.value (c:\Users\lonni\.vscode\extensions\charliermarsh.ruff-2024.50.0-win32-x64\dist\extension.js:1:397249)
	```

lsouder-ozone3d avatar Sep 20 '24 19:09 lsouder-ozone3d

Related: https://github.com/astral-sh/ruff-vscode/issues/598

dhruvmanila avatar Oct 07 '24 13:10 dhruvmanila

In case it helps in debugging at all, after some fiddling, it seems setting "ruff.nativeServer": "off" seems to have fixed this for me.

lsouder-ozone3d avatar Oct 24 '24 18:10 lsouder-ozone3d

@lsouder-ozone3d I'm not sure that the logs that you've provided are from Ruff. You've mentioned "Extension host" but that's not related to Ruff. Can you open a new issue with the logs from Ruff? Refer to the troubleshooting guide.

dhruvmanila avatar Oct 25 '24 04:10 dhruvmanila

I'm going to merge this into #598

dhruvmanila avatar Oct 25 '24 04:10 dhruvmanila

@lsouder-ozone3d Ok, I think it might be related to ruff.interpreter setting. Can you provide all the Ruff settings that you've configured?

dhruvmanila avatar Oct 25 '24 04:10 dhruvmanila

@dhruvmanila The setting mentioned in the comment above is the only setting I have set for Ruff. Previously, I was running with all defaults.

lsouder-ozone3d avatar Nov 04 '24 16:11 lsouder-ozone3d

@lsouder-ozone3d do you still face the same problem? Can you open a new issue with some details to help us debug?

dhruvmanila avatar Nov 05 '24 03:11 dhruvmanila

I'm seeing this issue as well. i've tried the troubleshooting steps and the steps here but I am unable to get any logs. it looks like the process just gets stuck in a zombie state. I can see heaps of instances of the language server are running:

Image

stan-stately avatar Jan 23 '25 05:01 stan-stately

ok for me the fix was to point the interpreter at a python other than the default /opt/homebrew/bin/python3. It was enough just to do "ruff.interpreter": ["python"]. I also restarted vscode every time i changed the settings to ensure this zombie state above did not persist because i think maybe that blocked successful start.

I also couldn't use ~/python in ruff.interpreter. the extension was failing to expand the ~

unsure if it's relevant but im using "ruff.importStrategy": "useBundled"

stan-stately avatar Jan 23 '25 06:01 stan-stately

I'm seeing this issue as well. i've tried the troubleshooting steps and the steps here but I am unable to get any logs. it looks like the process just gets stuck in a zombie state. I can see heaps of instances of the language server are running:

This should be fixed with the unreleased version on main (https://github.com/astral-sh/ruff-vscode/commit/adb92f8e17d7da0dbc377aa6bda23f3c65629871). I'll release it today / tomorrow once the new version of Ruff is out.

unsure if it's relevant but im using "ruff.importStrategy": "useBundled"

This is relevant because when ruff.interpreter isn't used anywhere when the import strategy is useBundled as there's no need. Refer to the first point at https://docs.astral.sh/ruff/editors/settings/#interpreter.

dhruvmanila avatar Jan 23 '25 06:01 dhruvmanila