aboutsummaryrefslogtreecommitdiff
path: root/helix-lsp/src
diff options
context:
space:
mode:
authorPascal Kuthe2023-04-30 21:44:06 +0000
committerSkyler Hawthorne2023-05-01 00:26:40 +0000
commit75f62bc86f2ccf2f529d4faa45aed08adfefef78 (patch)
treec0431e0d0bab1d8cb6e14b651bc5a469e2405bbf /helix-lsp/src
parentb0b3f45b80931e73eadaf7e73f1981283b8e49fc (diff)
fix didChange notifaction offset encoding
Diffstat (limited to 'helix-lsp/src')
-rw-r--r--helix-lsp/src/client.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs
index 89b714e2..840e7382 100644
--- a/helix-lsp/src/client.rs
+++ b/helix-lsp/src/client.rs
@@ -645,7 +645,11 @@ impl Client {
// Calculation is therefore a bunch trickier.
use helix_core::RopeSlice;
- fn traverse(pos: lsp::Position, text: RopeSlice) -> lsp::Position {
+ fn traverse(
+ pos: lsp::Position,
+ text: RopeSlice,
+ offset_encoding: OffsetEncoding,
+ ) -> lsp::Position {
let lsp::Position {
mut line,
mut character,
@@ -662,7 +666,11 @@ impl Client {
line += 1;
character = 0;
} else {
- character += ch.len_utf16() as u32;
+ character += match offset_encoding {
+ OffsetEncoding::Utf8 => ch.len_utf8() as u32,
+ OffsetEncoding::Utf16 => ch.len_utf16() as u32,
+ OffsetEncoding::Utf32 => 1,
+ };
}
}
lsp::Position { line, character }
@@ -683,7 +691,7 @@ impl Client {
}
Delete(_) => {
let start = pos_to_lsp_pos(new_text, new_pos, offset_encoding);
- let end = traverse(start, old_text.slice(old_pos..old_end));
+ let end = traverse(start, old_text.slice(old_pos..old_end), offset_encoding);
// deletion
changes.push(lsp::TextDocumentContentChangeEvent {
@@ -700,7 +708,8 @@ impl Client {
// a subsequent delete means a replace, consume it
let end = if let Some(Delete(len)) = iter.peek() {
old_end = old_pos + len;
- let end = traverse(start, old_text.slice(old_pos..old_end));
+ let end =
+ traverse(start, old_text.slice(old_pos..old_end), offset_encoding);
iter.next();