lsp: Move timeouts into client.request
This commit is contained in:
parent
b2800489de
commit
941c34a7fc
4 changed files with 14 additions and 11 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -527,6 +527,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"shellexpand",
|
||||
"smol",
|
||||
"smol-timeout",
|
||||
"thiserror",
|
||||
"url",
|
||||
]
|
||||
|
|
|
@ -13,6 +13,7 @@ once_cell = "1.4"
|
|||
|
||||
lsp-types = { version = "0.86", features = ["proposed"] }
|
||||
smol = "1.2"
|
||||
smol-timeout = "0.6"
|
||||
url = "2"
|
||||
pathdiff = "0.2"
|
||||
shellexpand = "2.0"
|
||||
|
|
|
@ -114,7 +114,14 @@ impl Client {
|
|||
.await
|
||||
.map_err(|e| Error::Other(e.into()))?;
|
||||
|
||||
let response = rx.recv().await.map_err(|e| Error::Other(e.into()))??;
|
||||
use smol_timeout::TimeoutExt;
|
||||
use std::time::Duration;
|
||||
|
||||
let response = match rx.recv().timeout(Duration::from_secs(2)).await {
|
||||
Some(response) => response,
|
||||
None => return Err(Error::Timeout),
|
||||
}
|
||||
.map_err(|e| Error::Other(e.into()))??;
|
||||
|
||||
let response = serde_json::from_value(response)?;
|
||||
|
||||
|
|
|
@ -857,21 +857,15 @@ pub fn completion(cx: &mut Context) {
|
|||
let language_server = cx.language_servers.get("rust", &cx.executor).unwrap();
|
||||
use log::info;
|
||||
|
||||
use smol_timeout::TimeoutExt;
|
||||
use std::time::Duration;
|
||||
|
||||
// TODO: blocking here is not ideal
|
||||
let pos = helix_lsp::util::pos_to_lsp_pos(
|
||||
&cx.view.doc.text().slice(..),
|
||||
cx.view.doc.selection().cursor(),
|
||||
);
|
||||
let res = smol::block_on(
|
||||
language_server
|
||||
.completion(cx.view.doc.identifier(), pos)
|
||||
.timeout(Duration::from_secs(2)),
|
||||
)
|
||||
.expect("completion failed!")
|
||||
.unwrap_or_default(); // if timeout, just return
|
||||
|
||||
// TODO: handle fails
|
||||
let res = smol::block_on(language_server.completion(cx.view.doc.identifier(), pos))
|
||||
.unwrap_or_default();
|
||||
|
||||
// TODO: if no completion, show some message or something
|
||||
if !res.is_empty() {
|
||||
|
|
Loading…
Add table
Reference in a new issue