fix didChange notifaction offset encoding

pull/6927/head
Pascal Kuthe 2 years ago committed by Skyler Hawthorne
parent b0b3f45b80
commit 75f62bc86f

@ -645,7 +645,11 @@ impl Client {
// Calculation is therefore a bunch trickier. // Calculation is therefore a bunch trickier.
use helix_core::RopeSlice; 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 { let lsp::Position {
mut line, mut line,
mut character, mut character,
@ -662,7 +666,11 @@ impl Client {
line += 1; line += 1;
character = 0; character = 0;
} else { } 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 } lsp::Position { line, character }
@ -683,7 +691,7 @@ impl Client {
} }
Delete(_) => { Delete(_) => {
let start = pos_to_lsp_pos(new_text, new_pos, offset_encoding); 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 // deletion
changes.push(lsp::TextDocumentContentChangeEvent { changes.push(lsp::TextDocumentContentChangeEvent {
@ -700,7 +708,8 @@ impl Client {
// a subsequent delete means a replace, consume it // a subsequent delete means a replace, consume it
let end = if let Some(Delete(len)) = iter.peek() { let end = if let Some(Delete(len)) = iter.peek() {
old_end = old_pos + len; 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(); iter.next();

Loading…
Cancel
Save