@@ -2,6 +2,8 @@ mod transport;
22
33use transport::{Payload, Transport};
44
5+use helix_core::{State, Transaction};
6+
57// use std::collections::HashMap;
68
79use jsonrpc_core as jsonrpc;
@@ -13,14 +15,24 @@ use serde::{Deserialize, Serialize};
1315pub use lsp::Position;
1416pub use lsp::Url;
1517
16−use smol::prelude::*;
1718use smol::{
1819 channel::{Receiver, Sender},
1920 io::{BufReader, BufWriter},
21+ // prelude::*,
2022 process::{Child, ChildStderr, Command, Stdio},
2123 Executor,
2224};
2325
26+pub mod util {
27+ use super::*;
28+
29+ pub fn lsp_pos_to_pos(doc: &helix_core::RopeSlice, pos: lsp::Position) -> usize {
30+ let line = doc.line_to_char(pos.line as usize);
31+ let line_start = doc.char_to_utf16_cu(line);
32+ doc.utf16_cu_to_char(pos.character as usize + line_start)
33+ }
34+}
35+
2436/// A type representing all possible values sent from the server to the client.
2537#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
2638#[serde(deny_unknown_fields)]
@@ -58,7 +70,7 @@ impl Notification {
5870}
5971
6072pub struct Client {
61− process: Child,
73+ _process: Child,
6274 stderr: BufReader<ChildStderr>,
6375
6476 outgoing: Sender<Payload>,
@@ -90,7 +102,7 @@ impl Client {
90102 let (incoming, outgoing) = Transport::start(ex, reader, writer);
91103
92104 Client {
93− process,
105+ _process: process,
94106 stderr,
95107
96108 outgoing,
@@ -224,15 +236,12 @@ impl Client {
224236 // Text document
225237 // -------------------------------------------------------------------------------------------
226238
227− pub async fn text_document_did_open(
228− &mut self,
229− state: &helix_core::State,
230− ) -> anyhow::Result<()> {
239+ pub async fn text_document_did_open(&mut self, state: &State) -> anyhow::Result<()> {
231240 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
232241 text_document: lsp::TextDocumentItem {
233242 uri: lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
234243 language_id: "rust".to_string(), // TODO: hardcoded for now
235− version: 0,
244+ version: state.version,
236245 text: String::from(&state.doc),
237246 },
238247 })
@@ -242,14 +251,15 @@ impl Client {
242251 // TODO: trigger any time history.commit_revision happens
243252 pub async fn text_document_did_change(
244253 &mut self,
245− state: &helix_core::State,
254+ state: &State,
255+ transaction: &Transaction,
246256 ) -> anyhow::Result<()> {
247257 self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
248258 text_document: lsp::VersionedTextDocumentIdentifier::new(
249259 lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
250− 0, // TODO: version
260+ state.version,
251261 ),
252− content_changes: vec![], // TODO:
262+ content_changes: vec![], // TODO: probably need old_state here too?
253263 })
254264 .await
255265 }