diff options
author | Gokul Soumya | 2022-07-22 16:23:08 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-07-29 05:31:21 +0000 |
commit | a8b123fe177d8cd7f5a610a0a50c16c9f64069bd (patch) | |
tree | d2718d2b4dccf0f1beb808b4fbb85c61a6e75382 /helix-term/src | |
parent | 14eca318a772353a3bfa2d86c196572e25497132 (diff) |
Fix byte index error in signature help highlighting
The language server sends a char offset range within the
signature help label text to highlight as the current parameter,
but helix uses byte offset ranges for rendering highlights. This
was brought up in the [review of the original signature help PR][1],
but the ranges were being highlighted correctly, and there were no
out of bound or indexing panics. Turns out rust-analyzer was
[incorrectly sending byte offsets] instead of char offsets and this
made it seem like all was well and good with offsets in helix during
initial testing.
[1]: https://github.com/helix-editor/helix/pull/1755#discussion_r906715371
[2]: https://github.com/rust-lang/rust-analyzer/pull/12272
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands/lsp.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 1785a50c..38507e4d 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -904,7 +904,12 @@ pub fn signature_help_impl(cx: &mut Context, invoked: SignatureHelpInvoked) { Some((start, start + string.len())) } lsp::ParameterLabel::LabelOffsets([start, end]) => { - Some((*start as usize, *end as usize)) + // LS sends offsets based on utf-16 based string representation + // but highlighting in helix is done using byte offset. + use helix_core::str_utils::char_to_byte_idx; + let from = char_to_byte_idx(&signature.label, *start as usize); + let to = char_to_byte_idx(&signature.label, *end as usize); + Some((from, to)) } } }; |