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

Ruff crashed workspace URL was not a file path! #12660

Closed
Odud opened this issue Aug 4, 2024 · 13 comments · Fixed by #12725
Closed

Ruff crashed workspace URL was not a file path! #12660

Odud opened this issue Aug 4, 2024 · 13 comments · Fixed by #12725
Assignees
Labels
server Related to the LSP server

Comments

@Odud
Copy link

Odud commented Aug 4, 2024

I'm trying to install and use ruff with Vscode on Windows 10
I've installed ruff with python -m pip install ruff and then the vsode extension but on starting vscode I get the message saying that the Ruff server crashed 5 times in the last 3 minutes. The server will not be restarted. The output looks like this:

2024-08-04 10:36:18.577 [info] Name: Ruff
2024-08-04 10:36:18.577 [info] Module: ruff
2024-08-04 10:36:18.577 [info] Python extension loading
2024-08-04 10:36:18.577 [info] Waiting for interpreter from python extension.
2024-08-04 10:36:18.577 [info] Python extension loaded
2024-08-04 10:36:18.577 [info] Using interpreter: c:\Users\langb\AppData\Local\Programs\Python\Python312\python.exe
2024-08-04 10:36:18.648 [info] Using the Ruff binary: c:\Users\langb\AppData\Local\Programs\Python\Python312\Scripts\ruff.exe
2024-08-04 10:36:18.998 [info] Resolved 'ruff.nativeServer: auto' to use the native server
2024-08-04 10:36:19.000 [info] Found Ruff 0.5.6 at c:\Users\langb\AppData\Local\Programs\Python\Python312\Scripts\ruff.exe
2024-08-04 10:36:19.000 [info] Server run command: c:\Users\langb\AppData\Local\Programs\Python\Python312\Scripts\ruff.exe server
2024-08-04 10:36:19.001 [info] Server: Start requested.
2024-08-04 10:36:19.058 [info] ruff failed
  Cause: workspace URL was not a file path!

Contents of pyproject.toml (in .vscode\extensions\charliermarsh.ruff-2024.36.0-win32-x64)

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "ruff-vscode"
version = "2024.36.0"
description = "A Visual Studio Code extension with support for the Ruff linter."
authors = [{ name = "Charlie Marsh", email = "[email protected]" }]
maintainers = [{ name = "Charlie Marsh", email = "[email protected]" }]
requires-python = ">=3.7"
license = "MIT"
dependencies = ["packaging>=23.1", "ruff-lsp==0.0.54", "ruff==0.5.4"]

[project.optional-dependencies]
dev = ["mypy==1.2.0", "python-lsp-jsonrpc==1.0.0"]

[tool.ruff]
line-length = 88
target-version = "py37"
extend-exclude = ["bundled/libs", "scr/testFixture"]

[tool.ruff.lint]
select = ["E", "F", "W", "Q", "UP", "I", "N"]

[tool.mypy]
files = ["bundled/tool", "build", "tests"]
no_implicit_optional = true
check_untyped_defs = true

[[tool.mypy.overrides]]
module = ["debugpy.*", "lsprotocol.*", "pygls.*", "pylsp_jsonrpc.*"]
ignore_missing_imports = true

I've tried python -m pip uninstall ruff and uninstalling the extension, followed by reinstall but this has made no difference.

@MichaReiser MichaReiser added the server Related to the LSP server label Aug 4, 2024
@dhruvmanila
Copy link
Member

Can you turn on verbose logging using the following config and provide the logs? I'm specifically interested in the initialization parameters the client is providing to the editor.

{
	"ruff.trace.server": "verbose"
}

(Assuming that you're using VS Code based on the provided logs)

It's this method (to_file_path) which is failing.

@dhruvmanila
Copy link
Member

Also, the pyproject.toml config that you've provided is the one from astral-sh/ruff-vscode extension. Can you provide the path to the folder that's open in VS Code?

@Odud
Copy link
Author

Odud commented Aug 5, 2024 via email

@dhruvmanila
Copy link
Member

Logging output attached.

I'm sorry but I don't see anything attached to your latest message.

Regarding your second request I can't find a pyproject.toml (or ruff.toml or .ruff.toml) anywhere in my working directory structure other than the ones I found in astral-sh/ruff-vscode. Please tell me where to look.

It's fine if there's no config files in your project.

@Odud
Copy link
Author

Odud commented Aug 5, 2024 via email

@dhruvmanila
Copy link
Member

Sorry about that, here it is. I've tried to attach it again.

Unfortunately, I don't see it :(

I'm guessing one can't include attachments when replying to GitHub issue via email.

@Odud
Copy link
Author

Odud commented Aug 5, 2024

Trying though github this time, seems to have taken the attachment
Ruff.log

@Odud
Copy link
Author

Odud commented Aug 5, 2024

So I think I know what is causing it, but not why. At the end of my vscode workspace file I had the following lines

        {
            "name": "Pico (W) Remote Workspace",
            "uri": "pico:"
        }

This was a hangover from when I was doing some Pico development in the same workspace. I've now removed it and restarted Vscode and I haven't seen anymore crashes in Ruff. Ruff is reporting code issues correctly now.

@dhruvmanila
Copy link
Member

Yeah, I see the issue. The workspace URI is different than what's expected ("pico:" instead of "file:"). I'm not sure if that's intentional but I wonder if we should ignore the workspace instead of throwing an error and log it as a warning.

@dhruvmanila
Copy link
Member

Thanks for providing the logs!

@Odud
Copy link
Author

Odud commented Aug 5, 2024 via email

@dhruvmanila
Copy link
Member

My guess would be it is best to ignore rather than error.

Yeah, I agree.

@dhruvmanila dhruvmanila self-assigned this Aug 5, 2024
dhruvmanila added a commit that referenced this issue Aug 7, 2024
## Summary

This PR updates the server to ignore non-file workspace URL.

This is to avoid crashing the server if the URL scheme is not "file".
We'd still raise an error if the URL to file path conversion fails.

Also, as per the docs of
[`to_file_path`](https://docs.rs/url/2.5.2/url/struct.Url.html#method.to_file_path):

> Note: This does not actually check the URL’s scheme, and may give
nonsensical results for other schemes. It is the user’s responsibility
to check the URL’s scheme before calling this.

resolves: #12660

## Test Plan

I'm not sure how to test this locally but the change is small enough to
validate on its own.
@Odud
Copy link
Author

Odud commented Aug 7, 2024 via email

dylwil3 pushed a commit to dylwil3/ruff that referenced this issue Aug 7, 2024
## Summary

This PR updates the server to ignore non-file workspace URL.

This is to avoid crashing the server if the URL scheme is not "file".
We'd still raise an error if the URL to file path conversion fails.

Also, as per the docs of
[`to_file_path`](https://docs.rs/url/2.5.2/url/struct.Url.html#method.to_file_path):

> Note: This does not actually check the URL’s scheme, and may give
nonsensical results for other schemes. It is the user’s responsibility
to check the URL’s scheme before calling this.

resolves: astral-sh#12660

## Test Plan

I'm not sure how to test this locally but the change is small enough to
validate on its own.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Related to the LSP server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants