Skip to content

ruff server default to current working directory in environments without any root directories or workspaces#10398

Merged
snowsignal merged 2 commits intomainfrom
jane/server/root-uri
Mar 18, 2024
Merged

ruff server default to current working directory in environments without any root directories or workspaces#10398
snowsignal merged 2 commits intomainfrom
jane/server/root-uri

Conversation

@snowsignal
Copy link
Copy Markdown
Contributor

@snowsignal snowsignal commented Mar 14, 2024

Summary

Fixes #10324

This removes an overeager failure case where we would exit early if no root directory or workspace folders were provided on server initialization. We now fall-back to the current working directory as a workspace for that file.

Test Plan

N/A

@snowsignal snowsignal added the server Related to the LSP server label Mar 14, 2024
@snowsignal snowsignal requested a review from dhruvmanila March 14, 2024 00:15
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 14, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dhruvmanila
Copy link
Copy Markdown
Member

Testing this out...

@dhruvmanila
Copy link
Copy Markdown
Member

It's not giving me any diagnostics. The LSP logs have this error:

[ERROR][2024-03-14 09:56:07] .../vim/lsp/rpc.lua:789	"rpc"	"/Users/dhruv/work/astral/ruff-test/target/release/ruff"	"stderr"	"┐ruff_server::server::api::notifications::did_open::run{file=file:///Users/dhruv/playground/python/animation.py}\n┘\n"

I suspect this is because there's no workspace associated with that document, so the did_open notification is failing?

@snowsignal
Copy link
Copy Markdown
Contributor Author

@dhruvmanila Right, it's failing to open because the file isn't associated with any workspace. The assumption that the server has made up until now is that any file being opened by the editor would have an associated workspace folder the client would have previously told us about, but this is clearly not the case.

@snowsignal
Copy link
Copy Markdown
Contributor Author

Actually, maybe what we need to do is just always create a new workspace in the session as a fallback mechanism if an file being opened isn't in a workspace path already.

Copy link
Copy Markdown
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I tested out using diagnostics, code actions, formatting and range formatting. It works well. LGTM!

@MichaReiser MichaReiser changed the title ruff server now works in environments without any root directories or workspaces ruff server default to current working directory in environments without any root directories or workspaces Mar 18, 2024
@snowsignal snowsignal merged commit 93566f9 into main Mar 18, 2024
@snowsignal snowsignal deleted the jane/server/root-uri branch March 18, 2024 15:46
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 this pull request may close these issues.

Server fails to start if there's not root directory provided

2 participants