Skip to content

Commit d25a676

Browse files
authored
Merge pull request rust-lang#20876 from rust-lang/push-lznzsmuxzsot
fix: Fix `signature_help` to proto conversion creating invalid utf16 offsets
2 parents 5057787 + b526310 commit d25a676

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
@@ -496,8 +496,15 @@ pub(crate) fn signature_help(
496496
.parameter_ranges()
497497
.iter()
498498
.map(|it| {
499-
let start = call_info.signature[..it.start().into()].chars().count() as u32;
500-
let end = call_info.signature[..it.end().into()].chars().count() as u32;
499+
let start = call_info.signature[..it.start().into()]
500+
.chars()
501+
.map(|c| c.len_utf16())
502+
.sum::<usize>() as u32;
503+
let end = start
504+
+ call_info.signature[it.start().into()..it.end().into()]
505+
.chars()
506+
.map(|c| c.len_utf16())
507+
.sum::<usize>() as u32;
501508
[start, end]
502509
})
503510
.map(|label_offsets| lsp_types::ParameterInformation {
@@ -516,9 +523,9 @@ pub(crate) fn signature_help(
516523
label.push_str(", ");
517524
}
518525
first = false;
519-
let start = label.chars().count() as u32;
526+
let start = label.len() as u32;
520527
label.push_str(param);
521-
let end = label.chars().count() as u32;
528+
let end = label.len() as u32;
522529
params.push(lsp_types::ParameterInformation {
523530
label: lsp_types::ParameterLabel::LabelOffsets([start, end]),
524531
documentation: None,

0 commit comments

Comments
 (0)