@@ -5,7 +5,7 @@ use crate::{
6type Result<T> = core::result::Result<T, Error>;
6type Result<T> = core::result::Result<T, Error>;
8−use helix_core::{ChangeSet, Rope, Transaction};
8+use helix_core::{ChangeSet, Rope, RopeSlice, Transaction};
10// use std::collections::HashMap;
10// use std::collections::HashMap;
11use std::sync::atomic::{AtomicU64, Ordering};
11use std::sync::atomic::{AtomicU64, Ordering};
@@ -244,7 +244,10 @@ impl Client {
249+ changeset: &ChangeSet,
247− fn to_changes(changeset: &ChangeSet) -> Vec<lsp::TextDocumentContentChangeEvent> {
250+ ) -> Vec<lsp::TextDocumentContentChangeEvent> {
248 let mut iter = changeset.changes().iter().peekable();
251 let mut iter = changeset.changes().iter().peekable();
249 let mut old_pos = 0;
252 let mut old_pos = 0;
@@ -253,9 +256,9 @@ impl Client {
253 use crate::util::pos_to_lsp_pos;
256 use crate::util::pos_to_lsp_pos;
254 use helix_core::Operation::*;
257 use helix_core::Operation::*;
256− // TEMP
259+ let old_text = old_text.slice(..);
257− let rope = helix_core::Rope::from("");
260+
258− let old_text = rope.slice(..);
261+ // TODO: verify this function, specifically line num counting
260 while let Some(change) = iter.next() {
263 while let Some(change) = iter.next() {
261 let len = match change {
264 let len = match change {
@@ -290,21 +293,6 @@ impl Client {
292 Insert(s) => {
295 Insert(s) => {
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
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
308 let start = pos_to_lsp_pos(&old_text, old_pos);
296 let start = pos_to_lsp_pos(&old_text, old_pos);
310 // insert
298 // insert
@@ -325,6 +313,7 @@ impl Client {
325 pub async fn text_document_did_change(
313 pub async fn text_document_did_change(
327 text_document: lsp::VersionedTextDocumentIdentifier,
315 text_document: lsp::VersionedTextDocumentIdentifier,
328 changes: &ChangeSet,
317 changes: &ChangeSet,
329 ) -> Result<()> {
318 ) -> Result<()> {
330 // figure out what kind of sync the server supports
319 // figure out what kind of sync the server supports
@@ -350,7 +339,7 @@ impl Client {
350 text: "".to_string(),
339 text: "".to_string(),
351 }] // TODO: probably need old_state here too?
340 }] // TODO: probably need old_state here too?
353− lsp::TextDocumentSyncKind::Incremental => Self::to_changes(changes),
342+ lsp::TextDocumentSyncKind::Incremental => Self::to_changes(old_text, changes),
354 lsp::TextDocumentSyncKind::None => return Ok(()),
343 lsp::TextDocumentSyncKind::None => return Ok(()),