@@ -112,49 +112,49 @@ impl Client {
112112 R::Result: core::fmt::Debug, // TODO: temporary
113113 {
114114 // a future that resolves into the response
115− let future = self.call::<R>(params).await?;
116− let json = future.await?;
115+ let json = self.call::<R>(params).await?;
117116 let response = serde_json::from_value(json)?;
118117 Ok(response)
119118 }
120119
121120 /// Execute a RPC request on the language server.
122− pub async fn call<R: lsp::request::Request>(
121+ pub fn call<R: lsp::request::Request>(
123122 &self,
124123 params: R::Params,
125− ) -> Result<impl Future<Output = Result<Value>>>
124+ ) -> impl Future<Output = Result<Value>>
126125 where
127126 R::Params: serde::Serialize,
128127 {
129− let params = serde_json::to_value(params)?;
128+ let outgoing = self.outgoing.clone();
129+ let id = self.next_request_id();
130130
131− let request = jsonrpc::MethodCall {
132− jsonrpc: Some(jsonrpc::Version::V2),
133− id: self.next_request_id(),
134− method: R::METHOD.to_string(),
135− params: Self::value_into_params(params),
136− };
131+ async move {
132+ let params = serde_json::to_value(params)?;
137133
138− let (tx, mut rx) = channel::<Result<Value>>(1);
134+ let request = jsonrpc::MethodCall {
135+ jsonrpc: Some(jsonrpc::Version::V2),
136+ id,
137+ method: R::METHOD.to_string(),
138+ params: Self::value_into_params(params),
139+ };
139140
140− self.outgoing
141− .send(Payload::Request {
142− chan: tx,
143− value: request,
144− })
145− .map_err(|e| Error::Other(e.into()))?;
141+ let (tx, mut rx) = channel::<Result<Value>>(1);
146142
147− use std::time::Duration;
148− use tokio::time::timeout;
143+ outgoing
144+ .send(Payload::Request {
145+ chan: tx,
146+ value: request,
147+ })
148+ .map_err(|e| Error::Other(e.into()))?;
149+
150+ use std::time::Duration;
151+ use tokio::time::timeout;
149152
150− let future = async move {
151153 timeout(Duration::from_secs(2), rx.recv())
152154 .await
153155 .map_err(|e| Error::Timeout)? // return Timeout
154156 .unwrap() // TODO: None if channel closed
155− };
156−
157− Ok(future)
157+ }
158158 }
159159
160160 /// Send a RPC notification to the language server.
@@ -269,21 +269,21 @@ impl Client {
269269 self.request::<lsp::request::Shutdown>(()).await
270270 }
271271
272− pub async fn exit(&self) -> Result<()> {
273− self.notify::<lsp::notification::Exit>(()).await
272+ pub fn exit(&self) -> impl Future<Output = Result<()>> {
273+ self.notify::<lsp::notification::Exit>(())
274274 }
275275
276276 // -------------------------------------------------------------------------------------------
277277 // Text document
278278 // -------------------------------------------------------------------------------------------
279279
280− pub async fn text_document_did_open(
280+ pub fn text_document_did_open(
281281 &self,
282282 uri: lsp::Url,
283283 version: i32,
284284 doc: &Rope,
285285 language_id: String,
286− ) -> Result<()> {
286+ ) -> impl Future<Output = Result<()>> {
287287 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
288288 text_document: lsp::TextDocumentItem {
289289 uri,
@@ -292,7 +292,6 @@ impl Client {
292292 text: String::from(doc),
293293 },
294294 })
295− .await
296295 }
297296
298297 pub fn changeset_to_changes(
@@ -435,14 +434,13 @@ impl Client {
435434 ))
436435 }
437436
438− pub async fn text_document_did_close(
437+ pub fn text_document_did_close(
439438 &self,
440439 text_document: lsp::TextDocumentIdentifier,
441− ) -> Result<()> {
440+ ) -> impl Future<Output = Result<()>> {
442441 self.notify::<lsp::notification::DidCloseTextDocument>(lsp::DidCloseTextDocumentParams {
443442 text_document,
444443 })
445− .await
446444 }
447445
448446 // will_save / will_save_wait_until
@@ -477,11 +475,11 @@ impl Client {
477475 .await
478476 }
479477
480− pub async fn completion(
478+ pub fn completion(
481479 &self,
482480 text_document: lsp::TextDocumentIdentifier,
483481 position: lsp::Position,
484− ) -> Result<impl Future<Output = Result<Value>>> {
482+ ) -> impl Future<Output = Result<Value>> {
485483 // ) -> Result<Vec<lsp::CompletionItem>> {
486484 let params = lsp::CompletionParams {
487485 text_document_position: lsp::TextDocumentPositionParams {
@@ -499,7 +497,7 @@ impl Client {
499497 // lsp::CompletionContext { trigger_kind: , trigger_character: Some(), }
500498 };
501499
502− self.call::<lsp::request::Completion>(params).await
500+ self.call::<lsp::request::Completion>(params)
503501 }
504502
505503 pub async fn text_document_signature_help(