aboutsummaryrefslogtreecommitdiff
path: root/helix-lsp
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-12-25 08:42:50 +0000
committerBlaž Hrastnik2020-12-25 08:42:50 +0000
commit3cbab2090839ef0d0ca7d7d6ef01404e48ddc8fa (patch)
tree137dabf6c4a65bc5ac869f9b70c5bc720598d496 /helix-lsp
parent2ab069bb3fc815394cccca50378b62932f3146f5 (diff)
lsp: Fix pos_to_lsp_pos calculation.
Diffstat (limited to 'helix-lsp')
-rw-r--r--helix-lsp/src/client.rs31
-rw-r--r--helix-lsp/src/lib.rs2
-rw-r--r--helix-lsp/src/transport.rs3
3 files changed, 13 insertions, 23 deletions
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<T> = core::result::Result<T, Error>;
-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<lsp::TextDocumentContentChangeEvent> {
+ fn to_changes(
+ old_text: &Rope,
+ changeset: &ChangeSet,
+ ) -> Vec<lsp::TextDocumentContentChangeEvent> {
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();