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 server fails to work in Neovim or Helix when outside of a workspace #11236

Closed
snowsignal opened this issue May 2, 2024 · 3 comments · Fixed by #11497
Closed

ruff server fails to work in Neovim or Helix when outside of a workspace #11236

snowsignal opened this issue May 2, 2024 · 3 comments · Fixed by #11497
Assignees
Labels
bug Something isn't working server Related to the LSP server

Comments

@snowsignal
Copy link
Contributor

snowsignal commented May 2, 2024

By 'workspace', I mean a working directory that has a pyproject.toml/ruff.toml configuration file. When hx is used outside of a workspace, the server simply does not work with any opened files. None of the functions the server provides work as expected.

These are the associated error logs:

2024-05-01T20:30:48.048 helix_lsp::transport [ERROR] ruff err <- "├─   0.003277s   0ms WARN ruff_server::session::workspace Workspace not found for file:///<filepath>. Global settings will be used for this document\n"
2024-05-01T20:30:48.048 helix_lsp::transport [ERROR] ruff err <- "   0.003399s ERROR ruff_server::server::api An error occurred while running textDocument/didOpen: Unable to take snapshot for document with URL file:///<filepath>

My assumption is that we don't register a workspace on the server that can 'capture' the opened file, which means that the document is never registered as open (thus, we are unable to take a snapshot of it). We need a better way to handle documents outside of an existing workspace (the best solution may just be to instantiate a new workspace in the session when this happens).

Workaround

To work around this issue, create an empty configuration file from the directory where you launch the editor, using touch ruff.toml.

@snowsignal snowsignal added bug Something isn't working server Related to the LSP server labels May 2, 2024
@snowsignal snowsignal self-assigned this May 2, 2024
@dhruvmanila
Copy link
Member

Is this problem similar to the one solved in #10398 ?

@snowsignal
Copy link
Contributor Author

Yep, it's a related issue 👍

@snowsignal snowsignal changed the title ruff server fails to work in Helix when outside of a workspace ruff server fails to work in Neovim or Helix when outside of a workspace May 8, 2024
@snowsignal
Copy link
Contributor Author

Update: This is also happening on Neovim.

snowsignal added a commit that referenced this issue May 22, 2024
## Summary

Fixes #11236.

This PR fixes several issues, most of which relate to non-VS Code
editors (Helix and Neovim).

1. Global-only initialization options are now correctly deserialized
from Neovim and Helix
2. Empty diagnostics are now published correctly for Neovim and Helix.
3. A workspace folder is created at the current working directory if the
initialization parameters send an empty list of workspace folders.
4. The server now gracefully handles opening files outside of any known
workspace, and will use global fallback settings taken from client
editor settings and a user settings TOML, if it exists.

## Test Plan

I've tested to confirm that each issue has been fixed.

* Global-only initialization options are now correctly deserialized from
Neovim and Helix + the server gracefully handles opening files outside
of any known workspace


https://github.com/astral-sh/ruff/assets/19577865/4f33477f-20c8-4e50-8214-6608b1a1ea6b

* Empty diagnostics are now published correctly for Neovim and Helix


https://github.com/astral-sh/ruff/assets/19577865/c93f56a0-f75d-466f-9f40-d77f99cf0637

* A workspace folder is created at the current working directory if the
initialization parameters send an empty list of workspace folders.



https://github.com/astral-sh/ruff/assets/19577865/b4b2e818-4b0d-40ce-961d-5831478cc726
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants