Skip to content

Commit b526310

Browse files
committed
fix: Fix signature_help to proto conversion creating invalid utf16 offsets
1 parent a78b257 commit b526310

File tree

1 file changed

+11
-4
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/src/lsp

1 file changed

+11
-4
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,15 @@ pub(crate) fn signature_help(
493493
.parameter_ranges()
494494
.iter()
495495
.map(|it| {
496-
let start = call_info.signature[..it.start().into()].chars().count() as u32;
497-
let end = call_info.signature[..it.end().into()].chars().count() as u32;
496+
let start = call_info.signature[..it.start().into()]
497+
.chars()
498+
.map(|c| c.len_utf16())
499+
.sum::<usize>() as u32;
500+
let end = start
501+
+ call_info.signature[it.start().into()..it.end().into()]
502+
.chars()
503+
.map(|c| c.len_utf16())
504+
.sum::<usize>() as u32;
498505
[start, end]
499506
})
500507
.map(|label_offsets| lsp_types::ParameterInformation {
@@ -513,9 +520,9 @@ pub(crate) fn signature_help(
513520
label.push_str(", ");
514521
}
515522
first = false;
516-
let start = label.chars().count() as u32;
523+
let start = label.len() as u32;
517524
label.push_str(param);
518-
let end = label.chars().count() as u32;
525+
let end = label.len() as u32;
519526
params.push(lsp_types::ParameterInformation {
520527
label: lsp_types::ParameterLabel::LabelOffsets([start, end]),
521528
documentation: None,

0 commit comments

Comments
 (0)