Skip to content

Commit 5291145

Browse files
committed
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]: helix-editor#1755 (comment) [2]: rust-lang/rust-analyzer#12272
1 parent 19e51c8 commit 5291145

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

helix-term/src/commands/lsp.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -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
};

0 commit comments

Comments
 (0)