Skip to content

Commit 7959307

Browse files
committed
Auto merge of rust-lang#12272 - jonas-schievink:fix-signature-help-offsets, r=jonas-schievink
fix: Fix signature help LSP offset conversion Fixes rust-lang/rust-analyzer#12270 I don't think we really handle this correctly anywhere (eg. surrogates probably aren't counted right), but this at least fixes the immediately visible bug.
2 parents ee2cbe0 + 5ee028b commit 7959307

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

crates/rust-analyzer/src/to_proto.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ pub(crate) fn signature_help(
358358
let params = call_info
359359
.parameter_ranges()
360360
.iter()
361-
.map(|it| [u32::from(it.start()), u32::from(it.end())])
361+
.map(|it| {
362+
let start = call_info.signature[..it.start().into()].chars().count() as u32;
363+
let end = call_info.signature[..it.end().into()].chars().count() as u32;
364+
[start, end]
365+
})
362366
.map(|label_offsets| lsp_types::ParameterInformation {
363367
label: lsp_types::ParameterLabel::LabelOffsets(label_offsets),
364368
documentation: None,
@@ -375,9 +379,9 @@ pub(crate) fn signature_help(
375379
label.push_str(", ");
376380
}
377381
first = false;
378-
let start = label.len() as u32;
382+
let start = label.chars().count() as u32;
379383
label.push_str(param);
380-
let end = label.len() as u32;
384+
let end = label.chars().count() as u32;
381385
params.push(lsp_types::ParameterInformation {
382386
label: lsp_types::ParameterLabel::LabelOffsets([start, end]),
383387
documentation: None,

0 commit comments

Comments
 (0)