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: Unable to edit new, untitled files in VS Code #11510

Closed
T-256 opened this issue May 23, 2024 · 3 comments · Fixed by #11588
Closed

ruff server: Unable to edit new, untitled files in VS Code #11510

T-256 opened this issue May 23, 2024 · 3 comments · Fixed by #11588
Assignees
Labels
bug Something isn't working server Related to the LSP server

Comments

@T-256
Copy link
Contributor

T-256 commented May 23, 2024

VSCode Repro: Ctrl+Win+Alt+N -> select Python File

Output:

2024-05-23 13:52:40.699 [info] Name: Ruff
2024-05-23 13:52:40.700 [info] Module: ruff
2024-05-23 13:52:40.700 [info] Python extension loading
2024-05-23 13:52:40.700 [info] Waiting for interpreter from python extension.
2024-05-23 13:52:40.700 [info] Python extension loaded
2024-05-23 13:52:40.700 [info] Server run command: c:\Users\User\Desktop\test\.venv\Scripts\python.exe c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py server --preview
2024-05-23 13:52:40.700 [info] Server: Start requested.
2024-05-23 13:52:41.180 [info] [Trace - 1:52:41 PM] Received request 'client/registerCapability - (1)'.
2024-05-23 13:52:41.180 [info] [Trace - 1:52:41 PM] Sending response 'client/registerCapability - (1)'. Processing request took 0ms
2024-05-23 13:52:41.180 [info]    0.139395s INFO ruff_server::server Configuration file watcher successfully registered

2024-05-23 13:52:41.736 [info]    0.695387s WARN ruff_server::server::api Received notification $/setTrace which does not have a handler.

2024-05-23 13:52:41.770 [info]    0.729158s ERROR ruff_server::server::api An error occurred while running notebookDocument/didOpen: expected notebook URI untitled:Untitled-1.ipynb?jupyter-notebook to be a valid file path

2024-05-23 13:52:41.802 [info]    0.757168s WARN ruff_server::server::api Received notification $/setTrace which does not have a handler.

2024-05-23 13:52:43.029 [info]    1.956011s WARN ruff_server::server::api Received notification $/setTrace which does not have a handler.

2024-05-23 13:52:43.361 [info]    2.319372s WARN ruff_server::server::api Received notification $/setTrace which does not have a handler.

2024-05-23 13:52:43.698 [info]    2.657468s WARN ruff_server::server::api Received notification $/setTrace which does not have a handler.
@dhruvmanila dhruvmanila added bug Something isn't working server Related to the LSP server labels May 23, 2024
@snowsignal snowsignal self-assigned this May 23, 2024
@snowsignal snowsignal changed the title ruff server: Error on Untitled document ruff server: Unable to edit new, untitled files in VS Code May 23, 2024
@snowsignal
Copy link
Contributor

Thank you for opening this issue! I've made a small change to the issue title if that's okay with you 🙂

@T-256
Copy link
Contributor Author

T-256 commented May 24, 2024

Thank you for opening this issue! I've made a small change to the issue title if that's okay with you 🙂

Not only on editing Untitled-files but also, on opening them:

2024-05-23 13:55:32.141 [info]  171.100002s ERROR ruff_server::server::api An error occurred while running textDocument/didOpen: expected document URI untitled:Untitled-2 to be a valid file path

From what I understand, We could avoid using to_file_path method of lsp_types::Url to solve the problem for non-existent files on disk, so then no need PathBuf.

#[derive(Clone, Debug)]
pub(crate) enum DocumentKey {
Notebook(PathBuf),
NotebookCell(lsp_types::Url),
Text(PathBuf),
}

Unified lsp_types::Url expected at there, then all other urls with non-file: scheme would be handled.

@snowsignal
Copy link
Contributor

Right, at the moment the code assumes that text document URIs point to valid file paths. We'll have to rework how documents are indexed to fix this.

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.

4 participants