@@ -5,7 +5,7 @@ use crate::{
55
66type Result<T> = core::result::Result<T, Error>;
77
8−use helix_core::{ChangeSet, Rope, Transaction};
8+use helix_core::{ChangeSet, Rope, RopeSlice, Transaction};
99
1010// use std::collections::HashMap;
1111use std::sync::atomic::{AtomicU64, Ordering};
@@ -244,7 +244,10 @@ impl Client {
244244 .await
245245 }
246246
247− fn to_changes(changeset: &ChangeSet) -> Vec<lsp::TextDocumentContentChangeEvent> {
247+ fn to_changes(
248+ old_text: &Rope,
249+ changeset: &ChangeSet,
250+ ) -> Vec<lsp::TextDocumentContentChangeEvent> {
248251 let mut iter = changeset.changes().iter().peekable();
249252 let mut old_pos = 0;
250253
@@ -253,9 +256,9 @@ impl Client {
253256 use crate::util::pos_to_lsp_pos;
254257 use helix_core::Operation::*;
255258
256− // TEMP
257− let rope = helix_core::Rope::from("");
258− let old_text = rope.slice(..);
259+ let old_text = old_text.slice(..);
260+
261+ // TODO: verify this function, specifically line num counting
259262
260263 while let Some(change) = iter.next() {
261264 let len = match change {
@@ -290,21 +293,6 @@ impl Client {
290293 };
291294 }
292295 Insert(s) => {
293− // TODO:
294− // thread 'main' panicked at 'Attempt to index past end of slice: char index 1211, slice char length 0', /home/speed/.cargo/registry/src/github.com-1ecc6299db9ec823/ropey-1.2.0/src/slice.rs:301:9
295− // stack backtrace:
296− // 0: rust_begin_unwind
297− // at /rustc/b32e6e6ac8921035177256ab6806e6ab0d4b9b94/library/std/src/panicking.rs:493:5
298− // 1: std::panicking::begin_panic_fmt
299− // at /rustc/b32e6e6ac8921035177256ab6806e6ab0d4b9b94/library/std/src/panicking.rs:435:5
300− // 2: ropey::slice::RopeSlice::char_to_line
301− // at /home/speed/.cargo/registry/src/github.com-1ecc6299db9ec823/ropey-1.2.0/src/slice.rs:301:9
302− // 3: helix_lsp::util::pos_to_lsp_pos
303− // at /home/speed/src/helix/helix-lsp/src/lib.rs:39:20
304− // 4: helix_lsp::client::Client::to_changes
305− // at /home/speed/src/helix/helix-lsp/src/client.rs:293:33
306− // 5: helix_lsp::client::Client::text_document_did_change::{{closure}}
307− // at /home/speed/src/helix/helix-lsp/src/client.rs:338:55
308296 let start = pos_to_lsp_pos(&old_text, old_pos);
309297
310298 // insert
@@ -325,6 +313,7 @@ impl Client {
325313 pub async fn text_document_did_change(
326314 &self,
327315 text_document: lsp::VersionedTextDocumentIdentifier,
316+ old_text: &Rope,
328317 changes: &ChangeSet,
329318 ) -> Result<()> {
330319 // figure out what kind of sync the server supports
@@ -350,7 +339,7 @@ impl Client {
350339 text: "".to_string(),
351340 }] // TODO: probably need old_state here too?
352341 }
353− lsp::TextDocumentSyncKind::Incremental => Self::to_changes(changes),
342+ lsp::TextDocumentSyncKind::Incremental => Self::to_changes(old_text, changes),
354343 lsp::TextDocumentSyncKind::None => return Ok(()),
355344 };
356345