@@ -5,8 +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, Transaction};
8+use helix_core::{ChangeSet, Rope, Transaction};
9−use helix_view::Document;
11// use std::collections::HashMap;
10// use std::collections::HashMap;
12use std::sync::atomic::{AtomicU64, Ordering};
11use std::sync::atomic::{AtomicU64, Ordering};
@@ -23,10 +22,6 @@ use smol::{
26−fn text_document_identifier(doc: &Document) -> lsp::TextDocumentIdentifier {
27− lsp::TextDocumentIdentifier::new(lsp::Url::from_file_path(doc.path().unwrap()).unwrap())
30pub struct Client {
25pub struct Client {
31 _process: Child,
26 _process: Child,
32 stderr: BufReader<ChildStderr>,
27 stderr: BufReader<ChildStderr>,
@@ -232,13 +227,18 @@ impl Client {
232 // Text document
227 // Text document
233 // -------------------------------------------------------------------------------------------
228 // -------------------------------------------------------------------------------------------
235− pub async fn text_document_did_open(&self, doc: &Document) -> Result<()> {
230+ pub async fn text_document_did_open(
236 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
236 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
237 text_document: lsp::TextDocumentItem {
237 text_document: lsp::TextDocumentItem {
238− uri: lsp::Url::from_file_path(doc.path().unwrap()).unwrap(),
238+ uri,
239 language_id: "rust".to_string(), // TODO: hardcoded for now
239 language_id: "rust".to_string(), // TODO: hardcoded for now
240− version: doc.version,
240+ version,
241− text: String::from(doc.text()),
241+ text: String::from(doc),
@@ -290,6 +290,21 @@ impl Client {
292 Insert(s) => {
292 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
293 let start = pos_to_lsp_pos(&old_text, old_pos);
308 let start = pos_to_lsp_pos(&old_text, old_pos);
295 // insert
310 // insert
@@ -309,8 +324,8 @@ impl Client {
309 // TODO: trigger any time history.commit_revision happens
324 // TODO: trigger any time history.commit_revision happens
310 pub async fn text_document_did_change(
325 pub async fn text_document_did_change(
312− doc: &Document,
327+ text_document: lsp::VersionedTextDocumentIdentifier,
313− transaction: &Transaction,
328+ changes: &ChangeSet,
314 ) -> Result<()> {
329 ) -> Result<()> {
315 // figure out what kind of sync the server supports
330 // figure out what kind of sync the server supports
@@ -335,16 +350,12 @@ impl Client {
335 text: "".to_string(),
350 text: "".to_string(),
336 }] // TODO: probably need old_state here too?
351 }] // TODO: probably need old_state here too?
338− lsp::TextDocumentSyncKind::Incremental => Self::to_changes(transaction.changes()),
353+ lsp::TextDocumentSyncKind::Incremental => Self::to_changes(changes),
339 lsp::TextDocumentSyncKind::None => return Ok(()),
354 lsp::TextDocumentSyncKind::None => return Ok(()),
342 self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
357 self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
343− text_document: lsp::VersionedTextDocumentIdentifier::new(
358+ text_document,
344− // TODO: doc.into() Url
345− lsp::Url::from_file_path(doc.path().unwrap()).unwrap(),
348 content_changes: changes,
359 content_changes: changes,
@@ -352,9 +363,12 @@ impl Client {
353 // TODO: impl into() TextDocumentIdentifier / VersionedTextDocumentIdentifier for Document.
364 // TODO: impl into() TextDocumentIdentifier / VersionedTextDocumentIdentifier for Document.
355− pub async fn text_document_did_close(&self, doc: &Document) -> Result<()> {
366+ pub async fn text_document_did_close(
368+ text_document: lsp::TextDocumentIdentifier,
356 self.notify::<lsp::notification::DidCloseTextDocument>(lsp::DidCloseTextDocumentParams {
370 self.notify::<lsp::notification::DidCloseTextDocument>(lsp::DidCloseTextDocumentParams {
357− text_document: text_document_identifier(doc),
371+ text_document,
@@ -365,16 +379,17 @@ impl Client {
365 unimplemented!()
379 unimplemented!()
382+ pub async fn completion(
384+ text_document: lsp::TextDocumentIdentifier,
385+ position: lsp::Position,
368− pub async fn completion(&self, doc: &Document) -> anyhow::Result<Vec<lsp::CompletionItem>> {
386+ ) -> anyhow::Result<Vec<lsp::CompletionItem>> {
369 // TODO: figure out what should happen when you complete with multiple cursors
387 // TODO: figure out what should happen when you complete with multiple cursors
371 let params = lsp::CompletionParams {
389 let params = lsp::CompletionParams {
372 text_document_position: lsp::TextDocumentPositionParams {
390 text_document_position: lsp::TextDocumentPositionParams {
373− text_document: text_document_identifier(doc),
391+ text_document,
374− position: crate::util::pos_to_lsp_pos(
392+ position,
375− &doc.text().slice(..),
376− doc.selection().cursor(),
379 // TODO: support these tokens by async receiving and updating the choice list
394 // TODO: support these tokens by async receiving and updating the choice list
380 work_done_progress_params: lsp::WorkDoneProgressParams {
395 work_done_progress_params: lsp::WorkDoneProgressParams {