@@ -5,8 +5,7 @@ use crate::{
55
66type Result<T> = core::result::Result<T, Error>;
77
8−use helix_core::{ChangeSet, Transaction};
9−use helix_view::Document;
8+use helix_core::{ChangeSet, Rope, Transaction};
109
1110// use std::collections::HashMap;
1211use std::sync::atomic::{AtomicU64, Ordering};
@@ -23,10 +22,6 @@ use smol::{
2322 Executor,
2423};
2524
26−fn text_document_identifier(doc: &Document) -> lsp::TextDocumentIdentifier {
27− lsp::TextDocumentIdentifier::new(lsp::Url::from_file_path(doc.path().unwrap()).unwrap())
28−}
29−
3025pub struct Client {
3126 _process: Child,
3227 stderr: BufReader<ChildStderr>,
@@ -232,13 +227,18 @@ impl Client {
232227 // Text document
233228 // -------------------------------------------------------------------------------------------
234229
235− pub async fn text_document_did_open(&self, doc: &Document) -> Result<()> {
230+ pub async fn text_document_did_open(
231+ &self,
232+ uri: lsp::Url,
233+ version: i32,
234+ doc: &Rope,
235+ ) -> Result<()> {
236236 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
237237 text_document: lsp::TextDocumentItem {
238− uri: lsp::Url::from_file_path(doc.path().unwrap()).unwrap(),
238+ uri,
239239 language_id: "rust".to_string(), // TODO: hardcoded for now
240− version: doc.version,
241− text: String::from(doc.text()),
240+ version,
241+ text: String::from(doc),
242242 },
243243 })
244244 .await
@@ -290,6 +290,21 @@ impl Client {
290290 };
291291 }
292292 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
293308 let start = pos_to_lsp_pos(&old_text, old_pos);
294309
295310 // insert
@@ -309,8 +324,8 @@ impl Client {
309324 // TODO: trigger any time history.commit_revision happens
310325 pub async fn text_document_did_change(
311326 &self,
312− doc: &Document,
313− transaction: &Transaction,
327+ text_document: lsp::VersionedTextDocumentIdentifier,
328+ changes: &ChangeSet,
314329 ) -> Result<()> {
315330 // figure out what kind of sync the server supports
316331
@@ -335,16 +350,12 @@ impl Client {
335350 text: "".to_string(),
336351 }] // TODO: probably need old_state here too?
337352 }
338− lsp::TextDocumentSyncKind::Incremental => Self::to_changes(transaction.changes()),
353+ lsp::TextDocumentSyncKind::Incremental => Self::to_changes(changes),
339354 lsp::TextDocumentSyncKind::None => return Ok(()),
340355 };
341356
342357 self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
343− text_document: lsp::VersionedTextDocumentIdentifier::new(
344− // TODO: doc.into() Url
345− lsp::Url::from_file_path(doc.path().unwrap()).unwrap(),
346− doc.version,
347− ),
358+ text_document,
348359 content_changes: changes,
349360 })
350361 .await
@@ -352,9 +363,12 @@ impl Client {
352363
353364 // TODO: impl into() TextDocumentIdentifier / VersionedTextDocumentIdentifier for Document.
354365
355− pub async fn text_document_did_close(&self, doc: &Document) -> Result<()> {
366+ pub async fn text_document_did_close(
367+ &self,
368+ text_document: lsp::TextDocumentIdentifier,
369+ ) -> Result<()> {
356370 self.notify::<lsp::notification::DidCloseTextDocument>(lsp::DidCloseTextDocumentParams {
357− text_document: text_document_identifier(doc),
371+ text_document,
358372 })
359373 .await
360374 }
@@ -365,16 +379,17 @@ impl Client {
365379 unimplemented!()
366380 }
367381
368− pub async fn completion(&self, doc: &Document) -> anyhow::Result<Vec<lsp::CompletionItem>> {
382+ pub async fn completion(
383+ &self,
384+ text_document: lsp::TextDocumentIdentifier,
385+ position: lsp::Position,
386+ ) -> anyhow::Result<Vec<lsp::CompletionItem>> {
369387 // TODO: figure out what should happen when you complete with multiple cursors
370388
371389 let params = lsp::CompletionParams {
372390 text_document_position: lsp::TextDocumentPositionParams {
373− text_document: text_document_identifier(doc),
374− position: crate::util::pos_to_lsp_pos(
375− &doc.text().slice(..),
376− doc.selection().cursor(),
377− ),
391+ text_document,
392+ position,
378393 },
379394 // TODO: support these tokens by async receiving and updating the choice list
380395 work_done_progress_params: lsp::WorkDoneProgressParams {