rust-analyzer: Index out of bounds panic in line index
Rust analyzer panicked while commenting some code. I haven’t been able to reproduce the issue, but I decided to give you the output just in case. I was commenting either the ast::Statement enum or its Display implementation. If it helps the code I had can be found at https://github.com/tvallotton/sqlparser-rs/tree/rust-analyzer-panic.
Panic context:
>
version: d15f646ff 2021-08-30 stable
request: codeLens/resolve CodeLens {
range: Range {
start: Position {
line: 1351,
character: 11,
},
end: Position {
line: 1351,
character: 19,
},
},
command: None,
data: Some(
Object({
"impls": Object({
"textDocument": Object({
"uri": String(
"file:///Users/tomas/Documents/sqlparser-rs/src/ast/mod.rs",
),
}),
"position": Object({
"line": Number(
1351,
),
"character": Number(
11,
),
}),
}),
}),
),
}
thread '<unnamed>' panicked at 'index out of bounds: the len is 1153 but the index is 1351', crates/ide_db/src/line_index.rs:106:9
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: core::panicking::panic_bounds_check
3: rust_analyzer::from_proto::text_range
4: rust_analyzer::handlers::handle_code_lens_resolve
5: rust_analyzer::dispatch::RequestDispatcher::on::{{closure}}::{{closure}}
6: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 11:44:57 AM] Request codeLens/resolve failed.
Message: server panicked: index out of bounds: the len is 1153 but the index is 1351
Code: -32603
Panic context:
>
version: d15f646ff 2021-08-30 stable
request: codeLens/resolve CodeLens {
range: Range {
start: Position {
line: 1334,
character: 9,
},
end: Position {
line: 1334,
character: 20,
},
},
command: None,
data: Some(
Object({
"impls": Object({
"textDocument": Object({
"uri": String(
"file:///Users/tomas/Documents/sqlparser-rs/src/ast/mod.rs",
),
}),
"position": Object({
"line": Number(
1334,
),
"character": Number(
9,
),
}),
}),
}),
),
}
thread '<unnamed>' panicked at 'index out of bounds: the len is 1153 but the index is 1334', crates/ide_db/src/line_index.rs:106:9
Panic context:
>
version: d15f646ff 2021-08-30 stable
request: codeLens/resolve CodeLens {
range: Range {
start: Position {
line: 1321,
character: 11,
},
end: Position {
line: 1321,
character: 21,
},
},
command: None,
data: Some(
Object({
"impls": Object({
"textDocument": Object({
"uri": String(
"file:///Users/tomas/Documents/sqlparser-rs/src/ast/mod.rs",
),
}),
"position": Object({
"line": Number(
1321,
),
"character": Number(
11,
),
}),
}),
}),
),
}
thread '<unnamed>' panicked at 'index out of bounds: the len is 1153 but the index is 1321', crates/ide_db/src/line_index.rs:106:9
stack backtrace:
Panic context:
>
version: d15f646ff 2021-08-30 stable
request: codeLens/resolve CodeLens {
range: Range {
start: Position {
line: 1351,
character: 11,
},
end: Position {
line: 1351,
character: 19,
},
},
command: None,
data: Some(
Object({
"impls": Object({
"textDocument": Object({
"uri": String(
"file:///Users/tomas/Documents/sqlparser-rs/src/ast/mod.rs",
),
}),
"position": Object({
"line": Number(
1351,
),
"character": Number(
11,
),
}),
}),
}),
),
}
thread '<unnamed>' panicked at 'index out of bounds: the len is 1153 but the index is 1351', crates/ide_db/src/line_index.rs: 0: _rust_begin_unwind106
: 91:
core::panicking::panic_fmt
2: core::panicking::panic_bounds_check
3: rust_analyzer::from_proto::text_range
4: rust_analyzer::handlers::handle_code_lens_resolve
5: rust_analyzer::dispatch::RequestDispatcher::on::{{closure}}::{{closure}}
6: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: core::panicking::panic_bounds_check
3: rust_analyzer::from_proto::text_range
4: rust_analyzer::handlers::handle_code_lens_resolve
5: rust_analyzer::dispatch::RequestDispatcher::on::{{closure}}::{{closure}}
6: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: core::panicking::panic_bounds_check
3: rust_analyzer::from_proto::text_range
4: rust_analyzer::handlers::handle_code_lens_resolve
5: rust_analyzer::dispatch::RequestDispatcher::on::{{closure}[Error - 11:45:12 AM] Request codeLens/resolve failed.
Message: server panicked: index out of bounds: the len is 1153 but the index is 1334
Code: -32603
}::{{closure}}
6: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 11:45:12 AM] Request codeLens/resolve failed.
Message: server panicked: index out of bounds: the len is 1153 but the index is 1321
Code: -32603
[Error - 11:45:12 AM] Request codeLens/resolve failed.
Message: server panicked: index out of bounds: the len is 1153 but the index is 1351
Code: -32603
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 16 (14 by maintainers)
One hypothesis I have is maybe the clined indeed sends
DidChangeTextDocumentbetween asking for code lens and asking to resolve a specific code lens? One way to debug this is to add an optional memdoc document version to codelens data and verify, in resolve, that it is the same.But in general I think I see a bug here – we shouldn’t assume that between list/resolve calls the state of world doesn’t change. We shouldn’t be storying text ranges in the resolve data at all, for that matter.
Instead, we should use the pattern we employ for code actions and completion – re-run the same query, and use id of the result as data.
@tvallotton I think the right format is: