about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-05-16 13:50:00 +0000
committerbors <bors@rust-lang.org>2022-05-16 13:50:00 +0000
commit795930717b676ccf640c95756d2cba8770c4ef4e (patch)
tree18957dd435e27f65d1de82509a61d37215c1bf08
parentee2cbe0ae810cd8621662ac38f2c7a020d06620c (diff)
parent5ee028bbb8ccf1130f273192b68f07b82b3f1ae1 (diff)
downloadrust-795930717b676ccf640c95756d2cba8770c4ef4e.tar.gz
rust-795930717b676ccf640c95756d2cba8770c4ef4e.zip
Auto merge of #12272 - jonas-schievink:fix-signature-help-offsets, r=jonas-schievink
fix: Fix signature help LSP offset conversion

Fixes https://github.com/rust-lang/rust-analyzer/issues/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.
-rw-r--r--crates/rust-analyzer/src/to_proto.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 8669d5de37d..c0609f51874 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -358,7 +358,11 @@ pub(crate) fn signature_help(
             let params = call_info
                 .parameter_ranges()
                 .iter()
-                .map(|it| [u32::from(it.start()), u32::from(it.end())])
+                .map(|it| {
+                    let start = call_info.signature[..it.start().into()].chars().count() as u32;
+                    let end = call_info.signature[..it.end().into()].chars().count() as u32;
+                    [start, end]
+                })
                 .map(|label_offsets| lsp_types::ParameterInformation {
                     label: lsp_types::ParameterLabel::LabelOffsets(label_offsets),
                     documentation: None,
@@ -375,9 +379,9 @@ pub(crate) fn signature_help(
                     label.push_str(", ");
                 }
                 first = false;
-                let start = label.len() as u32;
+                let start = label.chars().count() as u32;
                 label.push_str(param);
-                let end = label.len() as u32;
+                let end = label.chars().count() as u32;
                 params.push(lsp_types::ParameterInformation {
                     label: lsp_types::ParameterLabel::LabelOffsets([start, end]),
                     documentation: None,