Skip to content

Commit

Permalink
Fix byte index error in signature help highlighting
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sudormrfbin committed Jul 23, 2022
1 parent 19e51c8 commit ba18489
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions helix-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ integration = []
helix-loader = { version = "0.6", path = "../helix-loader" }

ropey = { version = "1.5", default-features = false, features = ["simd"] }
str_indices = "0.4.0"
smallvec = "1.9"
smartstring = "1.0.1"
unicode-segmentation = "1.9"
Expand Down
7 changes: 6 additions & 1 deletion helix-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ pub fn find_root(root: Option<&str>, root_markers: &[String]) -> Option<std::pat
.cloned()
}

pub use ropey::{str_utils, Rope, RopeBuilder, RopeSlice};
pub use ropey::{Rope, RopeBuilder, RopeSlice};

pub mod str_utils {
pub use ropey::str_utils::*;
pub use str_indices::utf16;
}

// pub use tendril::StrTendril as Tendril;
pub use smartstring::SmartString;
Expand Down
7 changes: 6 additions & 1 deletion helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,12 @@ pub fn signature_help_impl(cx: &mut Context, invoked: SignatureHelpInvoked) {
Some((start, start + string.len()))
}
lsp::ParameterLabel::LabelOffsets([start, end]) => {
Some((*start as usize, *end as usize))
// LS sends offsets based on utf-16 based string representation
// but highlighting in helix is done using byte offset.
use helix_core::str_utils::utf16::to_byte_idx;
let from = to_byte_idx(&signature.label, *start as usize);
let to = to_byte_idx(&signature.label, *end as usize);
Some((from, to))
}
}
};
Expand Down

0 comments on commit ba18489

Please sign in to comment.