@@ -23,13 +23,16 @@ use smol::{
26+fn text_document_identifier(doc: &Document) -> lsp::TextDocumentIdentifier {
27+ lsp::TextDocumentIdentifier::new(lsp::Url::from_file_path(doc.path().unwrap()).unwrap())
26pub struct Client {
30pub struct Client {
27 _process: Child,
31 _process: Child,
28 stderr: BufReader<ChildStderr>,
32 stderr: BufReader<ChildStderr>,
30 outgoing: Sender<Payload>,
34 outgoing: Sender<Payload>,
31− pub incoming: Receiver<Call>,
35+ // pub incoming: Receiver<Call>,
33 pub request_counter: AtomicU64,
36 pub request_counter: AtomicU64,
35 capabilities: Option<lsp::ServerCapabilities>,
38 capabilities: Option<lsp::ServerCapabilities>,
@@ -38,7 +41,7 @@ pub struct Client {
40impl Client {
43impl Client {
41− pub fn start(ex: &Executor, cmd: &str, args: &[String]) -> Self {
44+ pub fn start(ex: &Executor, cmd: &str, args: &[String]) -> (Self, Receiver<Call>) {
42 let mut process = Command::new(cmd)
45 let mut process = Command::new(cmd)
43 .args(args)
46 .args(args)
44 .stdin(Stdio::piped())
47 .stdin(Stdio::piped())
@@ -55,18 +58,22 @@ impl Client {
56 let (incoming, outgoing) = Transport::start(ex, reader, writer);
59 let (incoming, outgoing) = Transport::start(ex, reader, writer);
58− Client {
61+ let client = Client {
59 _process: process,
62 _process: process,
63− incoming,
66+ // incoming,
65 request_counter: AtomicU64::new(0),
67 request_counter: AtomicU64::new(0),
67 capabilities: None,
69 capabilities: None,
68 // diagnostics: HashMap::new(),
70 // diagnostics: HashMap::new(),
73+ // TODO: async client.initialize()
74+ // maybe use an arc<atomic> flag
72 fn next_request_id(&self) -> jsonrpc::Id {
79 fn next_request_id(&self) -> jsonrpc::Id {
@@ -219,7 +226,7 @@ impl Client {
219 // Text document
226 // Text document
220 // -------------------------------------------------------------------------------------------
227 // -------------------------------------------------------------------------------------------
222− pub async fn text_document_did_open(&mut self, doc: &Document) -> Result<()> {
229+ pub async fn text_document_did_open(&self, doc: &Document) -> Result<()> {
223 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
230 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
224 text_document: lsp::TextDocumentItem {
231 text_document: lsp::TextDocumentItem {
225 uri: lsp::Url::from_file_path(doc.path().unwrap()).unwrap(),
232 uri: lsp::Url::from_file_path(doc.path().unwrap()).unwrap(),
@@ -295,7 +302,7 @@ impl Client {
296 // TODO: trigger any time history.commit_revision happens
303 // TODO: trigger any time history.commit_revision happens
297 pub async fn text_document_did_change(
304 pub async fn text_document_did_change(
298− &mut self,
305+ &self,
299 doc: &Document,
306 doc: &Document,
300 transaction: &Transaction,
307 transaction: &Transaction,
301 ) -> Result<()> {
308 ) -> Result<()> {
@@ -328,6 +335,7 @@ impl Client {
329 self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
336 self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
330 text_document: lsp::VersionedTextDocumentIdentifier::new(
337 text_document: lsp::VersionedTextDocumentIdentifier::new(
338+ // TODO: doc.into() Url
331 lsp::Url::from_file_path(doc.path().unwrap()).unwrap(),
339 lsp::Url::from_file_path(doc.path().unwrap()).unwrap(),
332 doc.version,
340 doc.version,
@@ -338,18 +346,16 @@ impl Client {
339 // TODO: impl into() TextDocumentIdentifier / VersionedTextDocumentIdentifier for Document.
347 // TODO: impl into() TextDocumentIdentifier / VersionedTextDocumentIdentifier for Document.
341− pub async fn text_document_did_close(&mut self, doc: &Document) -> Result<()> {
349+ pub async fn text_document_did_close(&self, doc: &Document) -> Result<()> {
342 self.notify::<lsp::notification::DidCloseTextDocument>(lsp::DidCloseTextDocumentParams {
350 self.notify::<lsp::notification::DidCloseTextDocument>(lsp::DidCloseTextDocumentParams {
343− text_document: lsp::TextDocumentIdentifier::new(
351+ text_document: text_document_identifier(doc),
344− lsp::Url::from_file_path(doc.path().unwrap()).unwrap(),
350 // will_save / will_save_wait_until
356 // will_save / will_save_wait_until
352− pub async fn text_document_did_save(&mut self) -> anyhow::Result<()> {
358+ pub async fn text_document_did_save(&self) -> anyhow::Result<()> {
353 unimplemented!()
359 unimplemented!()