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

Bad offset when inserting and removing newlines before a code lens quickly #12718

Closed
K4rakara opened this issue Jul 8, 2022 · 2 comments · Fixed by #14559
Closed

Bad offset when inserting and removing newlines before a code lens quickly #12718

K4rakara opened this issue Jul 8, 2022 · 2 comments · Fixed by #14559
Labels
Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@K4rakara
Copy link

K4rakara commented Jul 8, 2022

rust-analyzer version: rust-analyzer 1.64.0-nightly (75b2232 2022-07-03)
rustc version: rustc 1.64.0-nightly (7665c3543 2022-07-06)
relevant settings: I doubt these are really relevant but, CARGO_HOME=~/.var/app/org.rust-lang.Cargo, RUSTUP_HOME=~/.var/app/org.rust-lang.Rustup (I put all applications that install their own /opt/foo like directories in ~/.var/app because it declutters my home directory.

In VSCode, write the following (make sure to keep the leading and trailing newline):

extern crate foo;

pub enum Foo {
}

In between the extern crate foo; and pub enum Foo { lines, hold shift and try pressing enter, backspace, enter, backspace, repeatedly, and you should get a "A request has failed" notification. The panic message says something related to a bad range offset. I'm unsure of if this can occur with other items (functions, modules, etc), because I was unable to reproduce it with anything other than extern crate and enum. I'm guessing this is probably some kind of client synchronization issue, and if its just another case of a larger bug, I apologize.

Lastly, heres a video of the bug in action.

@lnicola
Copy link
Member

lnicola commented Jul 8, 2022

Good catch, I can confirm this reproduces. I wasn't able following the instructions, but it does happen if I type 2-3 newlines at a time (like in the video) instead of a single one. Holding Shift isn't required.

I think it only worked for you before the enum because of the "0 implementations" lens. Stack trace has:

thread 'Worker' panicked at 'Bad offset: range 0..36 offset 45'
[...]
   2: rowan::cursor::SyntaxNode::token_at_offset
   3: ide::goto_implementation::goto_implementation
   4: ide::annotations::resolve_annotation

Sometimes this doesn't show as a panic, but as a failed request (we probably handle the error in a different code path):

Request codeLens/resolve failed.
  Message: Invalid offset
  Code: -32603

@lnicola lnicola added S-actionable Someone could pick this issue up and work on it right now Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug labels Jul 8, 2022
@lnicola
Copy link
Member

lnicola commented Jul 8, 2022

Oh #4841 (comment).

@lnicola lnicola changed the title Creating and removing newlines while holding shift between certain items causes failed request Bad offset when inserting and removing newlines before a code lens quickly Jul 8, 2022
bors added a commit that referenced this issue Apr 13, 2023
internal: Skip code lens resolution for mismatched document versions

Closes #12718
bors added a commit that referenced this issue Apr 13, 2023
internal: Skip code lens resolution for mismatched document versions

Closes #12718
@bors bors closed this as completed in 41ee5ca Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants