kilbd / nova-rust

A Rust extension for the Nova text editor, using the Rust Analyzer language server.
MIT License
29 stars 5 forks source link

[BUG] Language Server Crash on trivial edits to new project #13

Closed lilyball closed 2 years ago

lilyball commented 2 years ago

Describe the bug I created a new project with cargo new foo, opened it in Nova, and began editing the main.rs file. And the language server keeps crashing on every edit. I restart it, it looks fine, I edit the file, crash.

Crash log ``` Rust Analyzer[11:13:31.012000] waiting for cargo metadata or cargo check Rust Analyzer[11:13:31.705000] waiting for cargo metadata or cargo check Rust Analyzer[11:13:31.754000] waiting for cargo metadata or cargo check Rust Analyzer[11:13:32.545000] content modified Rust Analyzer[11:13:33.574000] canceled by client Rust Analyzer[11:13:36.553000] canceled by client Rust Analyzer[11:13:36.670000] canceled by client Rust Analyzer[11:13:45.842000] Panic context: Rust Analyzer[11:13:45.842000] > Rust Analyzer[11:13:45.842000] version: ed4b312fa 2021-10-11 stable Rust Analyzer[11:13:45.842000] request: textDocument/codeAction CodeActionParams { Rust Analyzer[11:13:45.842000] text_document: TextDocumentIdentifier { Rust Analyzer[11:13:45.842000] uri: Url { Rust Analyzer[11:13:45.842000] scheme: "file", Rust Analyzer[11:13:45.842000] cannot_be_a_base: false, Rust Analyzer[11:13:45.842000] username: "", Rust Analyzer[11:13:45.842000] password: None, Rust Analyzer[11:13:45.842000] host: None, Rust Analyzer[11:13:45.842000] port: None, Rust Analyzer[11:13:45.842000] path: "/Volumes/Macintosh%20HD/Users/lily/Desktop/foo/src/main.rs", Rust Analyzer[11:13:45.842000] query: None, Rust Analyzer[11:13:45.842000] fragment: None, Rust Analyzer[11:13:45.842000] }, Rust Analyzer[11:13:45.842000] }, Rust Analyzer[11:13:45.842000] range: Range { Rust Analyzer[11:13:45.842000] start: Position { Rust Analyzer[11:13:45.842000] line: 5, Rust Analyzer[11:13:45.842000] character: 0, Rust Analyzer[11:13:45.842000] }, Rust Analyzer[11:13:45.842000] end: Position { Rust Analyzer[11:13:45.842000] line: 5, Rust Analyzer[11:13:45.842000] character: 0, Rust Analyzer[11:13:45.842000] }, Rust Analyzer[11:13:45.842000] }, Rust Analyzer[11:13:45.842000] context: CodeActionContext { Rust Analyzer[11:13:45.842000] diagnostics: [], Rust Analyzer[11:13:45.842000] only: None, Rust Analyzer[11:13:45.842000] }, Rust Analyzer[11:13:45.842000] work_done_progress_params: WorkDoneProgressParams { Rust Analyzer[11:13:45.842000] work_done_token: None, Rust Analyzer[11:13:45.842000] }, Rust Analyzer[11:13:45.842000] partial_result_params: PartialResultParams { Rust Analyzer[11:13:45.842000] partial_result_token: None, Rust Analyzer[11:13:45.842000] }, Rust Analyzer[11:13:45.842000] } Rust Analyzer[11:13:45.842000] Rust Analyzer[11:13:45.842000] thread '' panicked at 'index out of bounds: the len is 5 but the index is 5', crates/ide_db/src/line_index.rs:106:9 Rust Analyzer[11:13:45.842000] stack backtrace: Rust Analyzer[11:13:45.843000] Panic context: Rust Analyzer[11:13:45.843000] > Rust Analyzer[11:13:45.843000] version: ed4b312fa 2021-10-11 stable Rust Analyzer[11:13:45.843000] request: textDocument/completion CompletionParams { Rust Analyzer[11:13:45.843000] text_document_position: TextDocumentPositionParams { Rust Analyzer[11:13:45.843000] text_document: TextDocumentIdentifier { Rust Analyzer[11:13:45.843000] uri: Url { Rust Analyzer[11:13:45.843000] scheme: "file", Rust Analyzer[11:13:45.843000] cannot_be_a_base: false, Rust Analyzer[11:13:45.843000] username: "", Rust Analyzer[11:13:45.843000] password: None, Rust Analyzer[11:13:45.843000] host: None, Rust Analyzer[11:13:45.843000] port: None, Rust Analyzer[11:13:45.843000] path: "/Volumes/Macintosh%20HD/Users/lily/Desktop/foo/src/main.rs", Rust Analyzer[11:13:45.843000] query: None, Rust Analyzer[11:13:45.843000] fragment: None, Rust Analyzer[11:13:45.843000] }, Rust Analyzer[11:13:45.843000] }, Rust Analyzer[11:13:45.843000] position: Position { Rust Analyzer[11:13:45.843000] line: 5, Rust Analyzer[11:13:45.843000] character: 0, Rust Analyzer[11:13:45.843000] }, Rust Analyzer[11:13:45.843000] }, Rust Analyzer[11:13:45.843000] work_done_progress_params: WorkDoneProgressParams { Rust Analyzer[11:13:45.843000] work_done_token: None, Rust Analyzer[11:13:45.843000] }, Rust Analyzer[11:13:45.843000] partial_result_params: PartialResultParams { Rust Analyzer[11:13:45.843000] partial_result_token: None, Rust Analyzer[11:13:45.843000] }, Rust Analyzer[11:13:45.843000] context: Some( Rust Analyzer[11:13:45.843000] CompletionContext { Rust Analyzer[11:13:45.843000] trigger_kind: TriggerCharacter, Rust Analyzer[11:13:45.843000] trigger_character: Some( Rust Analyzer[11:13:45.843000] "f", Rust Analyzer[11:13:45.843000] ), Rust Analyzer[11:13:45.843000] }, Rust Analyzer[11:13:45.843000] ), Rust Analyzer[11:13:45.843000] } Rust Analyzer[11:13:45.843000] Rust Analyzer[11:13:45.843000] thread '' panicked at 'index out of bounds: the len is 5 but the index is 5', crates/ide_db/src/line_index.rs:106:9 Rust Analyzer[11:13:45.854000] 0: _rust_begin_unwind Rust Analyzer[11:13:45.854000] 1: core::panicking::panic_fmt Rust Analyzer[11:13:45.854000] 2: core::panicking::panic_bounds_check Rust Analyzer[11:13:45.854000] 3: rust_analyzer::from_proto::text_range Rust Analyzer[11:13:45.854000] 4: rust_analyzer::from_proto::file_range Rust Analyzer[11:13:45.854000] 5: rust_analyzer::handlers::handle_code_action Rust Analyzer[11:13:45.854000] 6: std::panicking::try Rust Analyzer[11:13:45.854000] 7: ::call_box Rust Analyzer[11:13:45.854000] note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Rust Analyzer[11:13:45.854000] stack backtrace: Rust Analyzer[11:13:45.854000] 0: _rust_begin_unwind Rust Analyzer[11:13:45.854000] 1: core::panicking::panic_fmt Rust Analyzer[11:13:45.854000] 2: core::panicking::panic_bounds_check Rust Analyzer[11:13:45.854000] 3: rust_analyzer::from_proto::file_position Rust Analyzer[11:13:45.854000] 4: rust_analyzer::handlers::handle_completion Rust Analyzer[11:13:45.854000] 5: std::panicking::try Rust Analyzer[11:13:45.854000] 6: ::call_box Rust Analyzer[11:13:45.854000] note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Rust Analyzer[11:13:45.855000] server panicked: index out of bounds: the len is 5 but the index is 5 Rust Analyzer[11:13:45.855000] server panicked: index out of bounds: the len is 5 but the index is 5 Rust Analyzer[11:13:46.012000] Panic context: Rust Analyzer[11:13:46.012000] > Rust Analyzer[11:13:46.012000] version: ed4b312fa 2021-10-11 stable Rust Analyzer[11:13:46.012000] notification: textDocument/didChange Rust Analyzer[11:13:46.012000] Rust Analyzer[11:13:46.012000] thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 5', crates/ide_db/src/line_index.rs:106:9 Rust Analyzer[11:13:46.012000] stack backtrace: Rust Analyzer[11:13:46.012000] 0: _rust_begin_unwind Rust Analyzer[11:13:46.012000] 1: core::panicking::panic_fmt Rust Analyzer[11:13:46.012000] 2: core::panicking::panic_bounds_check Rust Analyzer[11:13:46.012000] 3: rust_analyzer::from_proto::text_range Rust Analyzer[11:13:46.012000] 4: rust_analyzer::lsp_utils::apply_document_changes Rust Analyzer[11:13:46.012000] 5: core::ops::function::FnOnce::call_once Rust Analyzer[11:13:46.012000] 6: rust_analyzer::dispatch::NotificationDispatcher::on Rust Analyzer[11:13:46.012000] 7: rust_analyzer::main_loop::::handle_event Rust Analyzer[11:13:46.012000] 8: rust_analyzer::main_loop::::run Rust Analyzer[11:13:46.012000] 9: rust_analyzer::main_loop::main_loop Rust Analyzer[11:13:46.012000] 10: rust_analyzer::try_main Rust Analyzer[11:13:46.012000] 11: rust_analyzer::main Rust Analyzer[11:13:46.012000] note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Rust Analyzer[11:13:46.012000] thread '' panicked at 'called `Result::unwrap()` on an `Err` value: "SendError(..)"', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/lsp-server-0.5.2/src/stdio.rs:29:37 Rust Analyzer[11:13:46.012000] stack backtrace: Rust Analyzer[11:13:46.012000] 0: _rust_begin_unwind Rust Analyzer[11:13:46.012000] 1: core::panicking::panic_fmt Rust Analyzer[11:13:46.012000] 2: core::result::unwrap_failed Rust Analyzer[11:13:46.012000] note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Rust[11:13:46.329000] Error: Task “rust” exited with a non-zero exit status: 101. ```

To Reproduce Steps to reproduce the behavior:

  1. cargo new foo in the terminal
  2. Drag the new foo folder into Nova
  3. Open src/main.rs
  4. Edit the file

Additional information I haven't attempted to reproduce this with a fresh project.

In addition, after collecting that log, I cleared the console, opted to Restart Server, and then noticed that every cursor movement would log another panic (but would not tell me that the language server crashed). Hitting Save informed me of the crash again. I hit Restart Server again, and got

Rust Analyzer[11:18:54.454000] waiting for cargo metadata or cargo check
Rust Analyzer[11:18:56.002000] content modified

At this point every time I moved the cursor I'd get a line like

Rust Analyzer[11:18:56.878000] canceled by client

I hit Save again and this time it finally showed

Rust[11:19:05.080000]     Checking foo v0.1.0 (/Users/lily/Desktop/foo)
Rust[11:19:05.237000]     Finished dev [unoptimized + debuginfo] target(s) in 0.15s

Once I saw that, moving the cursor no longer logged anything, and I was able to make a trivial edit without logging too.

However, while writing up this report, after having left it alone for a while, I went back to Nova and inserted a single space at the end of the file, at which point the language server promptly crashed again.

Versions (please complete the following information):

lilyball commented 2 years ago

Playing some more, after a save and more of the canceled by client lines, waiting long enough will cause it to stop logging those. At this point I could make a trivial edit inside of my fn main() (inserting a space), or in between my struct Foo { … } and fn main() items, but once again, inserting a single space at the end of the file crashed the language server.

lilyball commented 2 years ago

It looks like the "index out of bounds" index is in fact the last line in the file.

Similarly, I deleted that blank line, at which point mere cursor interactions on what was now the last line caused panics.

So it looks like the core problem here is any editor interaction involving the last line of the file is panicking.

kilbd commented 2 years ago

Thank you for this detailed bug report!

You've definitely hit on an issue with the last line causing problems like "out of bounds" error with Rust Analyzer. I think this issue sounds like a core Nova bug I've heard of elsewhere, so it's not something I can fix. Other extensions have logged the same issue, and it's been mentioned multiple times in their extension developer forum. Panic is aware of the issue, but hasn't stated if a fix is imminent.

I've noticed the canceled by client log a lot too, so I need to dig into what's causing it. It did seem mostly benign (like maybe from mousing out of an identifier while it was in the middle of providing hover info), but I wanted to be sure when I had time.

kilbd commented 2 years ago

Like Code Actions, Panic appears to have fixed this issue in version 9 which was released today. Let me know if anyone still has this issue.