diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 7349792a..207e2970 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -5,7 +5,7 @@ use crate::{ type Result = core::result::Result; -use helix_core::{ChangeSet, Rope, Transaction}; +use helix_core::{ChangeSet, Rope, RopeSlice, Transaction}; // use std::collections::HashMap; use std::sync::atomic::{AtomicU64, Ordering}; @@ -244,7 +244,10 @@ impl Client { .await } - fn to_changes(changeset: &ChangeSet) -> Vec { + fn to_changes( + old_text: &Rope, + changeset: &ChangeSet, + ) -> Vec { let mut iter = changeset.changes().iter().peekable(); let mut old_pos = 0; @@ -253,9 +256,9 @@ impl Client { use crate::util::pos_to_lsp_pos; use helix_core::Operation::*; - // TEMP - let rope = helix_core::Rope::from(""); - let old_text = rope.slice(..); + let old_text = old_text.slice(..); + + // TODO: verify this function, specifically line num counting while let Some(change) = iter.next() { let len = match change { @@ -290,21 +293,6 @@ impl Client { }; } Insert(s) => { - // TODO: - // 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 - // stack backtrace: - // 0: rust_begin_unwind - // at /rustc/b32e6e6ac8921035177256ab6806e6ab0d4b9b94/library/std/src/panicking.rs:493:5 - // 1: std::panicking::begin_panic_fmt - // at /rustc/b32e6e6ac8921035177256ab6806e6ab0d4b9b94/library/std/src/panicking.rs:435:5 - // 2: ropey::slice::RopeSlice::char_to_line - // at /home/speed/.cargo/registry/src/github.com-1ecc6299db9ec823/ropey-1.2.0/src/slice.rs:301:9 - // 3: helix_lsp::util::pos_to_lsp_pos - // at /home/speed/src/helix/helix-lsp/src/lib.rs:39:20 - // 4: helix_lsp::client::Client::to_changes - // at /home/speed/src/helix/helix-lsp/src/client.rs:293:33 - // 5: helix_lsp::client::Client::text_document_did_change::{{closure}} - // at /home/speed/src/helix/helix-lsp/src/client.rs:338:55 let start = pos_to_lsp_pos(&old_text, old_pos); // insert @@ -325,6 +313,7 @@ impl Client { pub async fn text_document_did_change( &self, text_document: lsp::VersionedTextDocumentIdentifier, + old_text: &Rope, changes: &ChangeSet, ) -> Result<()> { // figure out what kind of sync the server supports @@ -350,7 +339,7 @@ impl Client { text: "".to_string(), }] // TODO: probably need old_state here too? } - lsp::TextDocumentSyncKind::Incremental => Self::to_changes(changes), + lsp::TextDocumentSyncKind::Incremental => Self::to_changes(old_text, changes), lsp::TextDocumentSyncKind::None => return Ok(()), }; diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 27a5e046..97afbca0 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -37,7 +37,7 @@ pub mod util { } pub fn pos_to_lsp_pos(doc: &RopeSlice, pos: usize) -> lsp::Position { let line = doc.char_to_line(pos); - let line_start = doc.char_to_utf16_cu(line); + let line_start = doc.char_to_utf16_cu(doc.line_to_char(line)); let col = doc.char_to_utf16_cu(pos) - line_start; lsp::Position::new(line as u32, col as u32) diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index 07c89fdd..15b15b85 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use log::debug; +use log::{debug, error}; use crate::{Error, Notification}; @@ -199,6 +199,7 @@ impl Transport { // server <- client msg = Self::recv(&mut self.reader, &mut self.headers).fuse() => { if msg.is_err() { + error!("err: <- {:?}", msg); break; } let msg = msg.unwrap(); diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 004c5c61..76b16743 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -207,7 +207,7 @@ impl Application { }), ); } - _ => unreachable!(), + e => unreachable!("{:?}", e), } } diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 785b0ca8..f32cca76 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -193,8 +193,11 @@ impl Document { // emit lsp notification if let Some(language_server) = &self.language_server { - let notify = language_server - .text_document_did_change(self.versioned_identifier(), transaction.changes()); + let notify = language_server.text_document_did_change( + self.versioned_identifier(), + &old_doc, + transaction.changes(), + ); smol::block_on(notify).expect("failed to emit textDocument/didChange"); }