on master help sign in
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

commita8b123fe177d8cd7f5a610a0a50c16c9f64069bd authorGokul Soumya <gokulps15@gmail.com> dateFri 22 Jul 2022, 21:53 (4 years ago) parent14eca31
1 file changed+6−1
helix-term/src/commands/lsp.rs+6−1
helix-term/src/commands/lsp.rs+6−1
@@ -904,7 +904,12 @@ pub fn signature_help_impl(cx: &mut Context, invoked: SignatureHelpInvoked) {
904904 Some((start, start + string.len()))
905905 }
906906 lsp::ParameterLabel::LabelOffsets([start, end]) => {
907− Some((*start as usize, *end as usize))
907+ // LS sends offsets based on utf-16 based string representation
908+ // but highlighting in helix is done using byte offset.
909+ use helix_core::str_utils::char_to_byte_idx;
910+ let from = char_to_byte_idx(&signature.label, *start as usize);
911+ let to = char_to_byte_idx(&signature.label, *end as usize);
912+ Some((from, to))
908913 }
909914 }
910915 };