@@ -2,6 +2,8 @@ mod transport;
3use transport::{Payload, Transport};
3use transport::{Payload, Transport};
5+use helix_core::{State, Transaction};
5// use std::collections::HashMap;
7// use std::collections::HashMap;
7use jsonrpc_core as jsonrpc;
9use jsonrpc_core as jsonrpc;
@@ -13,14 +15,24 @@ use serde::{Deserialize, Serialize};
13pub use lsp::Position;
15pub use lsp::Position;
14pub use lsp::Url;
16pub use lsp::Url;
17use smol::{
18use smol::{
18 channel::{Receiver, Sender},
19 channel::{Receiver, Sender},
19 io::{BufReader, BufWriter},
20 io::{BufReader, BufWriter},
20 process::{Child, ChildStderr, Command, Stdio},
22 process::{Child, ChildStderr, Command, Stdio},
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)
24/// A type representing all possible values sent from the server to the client.
36/// A type representing all possible values sent from the server to the client.
25#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
37#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
26#[serde(deny_unknown_fields)]
38#[serde(deny_unknown_fields)]
@@ -58,7 +70,7 @@ impl Notification {
60pub struct Client {
72pub struct Client {
61− process: Child,
73+ _process: Child,
62 stderr: BufReader<ChildStderr>,
74 stderr: BufReader<ChildStderr>,
64 outgoing: Sender<Payload>,
76 outgoing: Sender<Payload>,
@@ -90,7 +102,7 @@ impl Client {
90 let (incoming, outgoing) = Transport::start(ex, reader, writer);
102 let (incoming, outgoing) = Transport::start(ex, reader, writer);
93− process,
105+ _process: process,
96 outgoing,
108 outgoing,
@@ -224,15 +236,12 @@ impl Client {
224 // Text document
236 // Text document
225 // -------------------------------------------------------------------------------------------
237 // -------------------------------------------------------------------------------------------
227− pub async fn text_document_did_open(
239+ pub async fn text_document_did_open(&mut self, state: &State) -> anyhow::Result<()> {
229− state: &helix_core::State,
230− ) -> anyhow::Result<()> {
231 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
240 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
232 text_document: lsp::TextDocumentItem {
241 text_document: lsp::TextDocumentItem {
233 uri: lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
242 uri: lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
234 language_id: "rust".to_string(), // TODO: hardcoded for now
243 language_id: "rust".to_string(), // TODO: hardcoded for now
235− version: 0,
244+ version: state.version,
236 text: String::from(&state.doc),
245 text: String::from(&state.doc),
@@ -242,14 +251,15 @@ impl Client {
242 // TODO: trigger any time history.commit_revision happens
251 // TODO: trigger any time history.commit_revision happens
243 pub async fn text_document_did_change(
252 pub async fn text_document_did_change(
244 &mut self,
253 &mut self,
245− state: &helix_core::State,
254+ state: &State,
255+ transaction: &Transaction,
246 ) -> anyhow::Result<()> {
256 ) -> anyhow::Result<()> {
247 self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
257 self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
248 text_document: lsp::VersionedTextDocumentIdentifier::new(
258 text_document: lsp::VersionedTextDocumentIdentifier::new(
249 lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
259 lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
250− 0, // TODO: version
260+ state.version,
252− content_changes: vec![], // TODO:
262+ content_changes: vec![], // TODO: probably need old_state here too?