Skip to content

Commit ba18489

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][2] 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 ba18489

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helix-core/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ integration = []
1818
helix-loader = { version = "0.6", path = "../helix-loader" }
1919

2020
ropey = { version = "1.5", default-features = false, features = ["simd"] }
21+
str_indices = "0.4.0"
2122
smallvec = "1.9"
2223
smartstring = "1.0.1"
2324
unicode-segmentation = "1.9"

helix-core/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ pub fn find_root(root: Option<&str>, root_markers: &[String]) -> Option<std::pat
5252
.cloned()
5353
}
5454

55-
pub use ropey::{str_utils, Rope, RopeBuilder, RopeSlice};
55+
pub use ropey::{Rope, RopeBuilder, RopeSlice};
56+
57+
pub mod str_utils {
58+
pub use ropey::str_utils::*;
59+
pub use str_indices::utf16;
60+
}
5661

5762
// pub use tendril::StrTendril as Tendril;
5863
pub use smartstring::SmartString;

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::utf16::to_byte_idx;
910+
let from = to_byte_idx(&signature.label, *start as usize);
911+
let to = to_byte_idx(&signature.label, *end as usize);
912+
Some((from, to))
908913
}
909914
}
910915
};

0 commit comments

Comments
 (0)