diff options
Diffstat (limited to 'helix-lsp/src')
-rw-r--r-- | helix-lsp/src/client.rs | 24 | ||||
-rw-r--r-- | helix-lsp/src/lib.rs | 6 | ||||
-rw-r--r-- | helix-lsp/src/select_all.rs | 2 | ||||
-rw-r--r-- | helix-lsp/src/transport.rs | 6 |
4 files changed, 22 insertions, 16 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index e3f72a56..0cb09d76 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -5,7 +5,7 @@ use crate::{ type Result<T> = core::result::Result<T, Error>; -use helix_core::{ChangeSet, Rope, RopeSlice, Transaction}; +use helix_core::{ChangeSet, Rope}; // use std::collections::HashMap; use std::sync::atomic::{AtomicU64, Ordering}; @@ -18,13 +18,12 @@ use smol::{ channel::{Receiver, Sender}, io::{BufReader, BufWriter}, // prelude::*, - process::{Child, ChildStderr, Command, Stdio}, + process::{Child, Command, Stdio}, Executor, }; pub struct Client { _process: Child, - stderr: BufReader<ChildStderr>, outgoing: Sender<Payload>, // pub incoming: Receiver<Call>, @@ -51,11 +50,10 @@ impl Client { let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout")); let stderr = BufReader::new(process.stderr.take().expect("Failed to open stderr")); - let (incoming, outgoing) = Transport::start(ex, reader, writer); + let (incoming, outgoing) = Transport::start(ex, reader, writer, stderr); let client = Client { _process: process, - stderr, outgoing, // incoming, @@ -76,17 +74,15 @@ impl Client { jsonrpc::Id::Num(id) } - fn to_params(value: Value) -> Result<jsonrpc::Params> { + fn value_into_params(value: Value) -> jsonrpc::Params { use jsonrpc::Params; - let params = match value { + match value { Value::Null => Params::None, Value::Bool(_) | Value::Number(_) | Value::String(_) => Params::Array(vec![value]), Value::Array(vec) => Params::Array(vec), Value::Object(map) => Params::Map(map), - }; - - Ok(params) + } } /// Execute a RPC request on the language server. @@ -101,7 +97,7 @@ impl Client { jsonrpc: Some(jsonrpc::Version::V2), id: self.next_request_id(), method: R::METHOD.to_string(), - params: Self::to_params(params)?, + params: Self::value_into_params(params), }; let (tx, rx) = smol::channel::bounded::<Result<Value>>(1); @@ -143,7 +139,7 @@ impl Client { let notification = jsonrpc::Notification { jsonrpc: Some(jsonrpc::Version::V2), method: R::METHOD.to_string(), - params: Self::to_params(params)?, + params: Self::value_into_params(params), }; self.outgoing @@ -251,7 +247,7 @@ impl Client { .await } - fn to_changes( + fn changeset_to_changes( old_text: &Rope, changeset: &ChangeSet, ) -> Vec<lsp::TextDocumentContentChangeEvent> { @@ -346,7 +342,7 @@ impl Client { text: "".to_string(), }] // TODO: probably need old_state here too? } - lsp::TextDocumentSyncKind::Incremental => Self::to_changes(old_text, changes), + lsp::TextDocumentSyncKind::Incremental => Self::changeset_to_changes(old_text, changes), lsp::TextDocumentSyncKind::None => return Ok(()), }; diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 97afbca0..23c42712 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -104,6 +104,12 @@ pub struct Registry { pub incoming: SelectAll<Receiver<Call>>, } +impl Default for Registry { + fn default() -> Self { + Self::new() + } +} + impl Registry { pub fn new() -> Self { let mut inner = HashMap::new(); diff --git a/helix-lsp/src/select_all.rs b/helix-lsp/src/select_all.rs index 987f2a10..b0623203 100644 --- a/helix-lsp/src/select_all.rs +++ b/helix-lsp/src/select_all.rs @@ -119,7 +119,7 @@ where I: IntoIterator, I::Item: Stream + Unpin, { - let mut set = SelectAll::new(); + let set = SelectAll::new(); for stream in streams { set.push(stream); diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index 15b15b85..17566f8e 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use log::{debug, error}; -use crate::{Error, Notification}; +use crate::Error; type Result<T> = core::result::Result<T, Error>; @@ -48,6 +48,8 @@ pub(crate) struct Transport { writer: BufWriter<ChildStdin>, reader: BufReader<ChildStdout>, + #[allow(dead_code)] // TODO: handle stderr logs + stderr: BufReader<ChildStderr>, } impl Transport { @@ -55,6 +57,7 @@ impl Transport { ex: &Executor, reader: BufReader<ChildStdout>, writer: BufWriter<ChildStdin>, + stderr: BufReader<ChildStderr>, ) -> (Receiver<jsonrpc::Call>, Sender<Payload>) { let (incoming, rx) = smol::channel::unbounded(); let (tx, outgoing) = smol::channel::unbounded(); @@ -62,6 +65,7 @@ impl Transport { let transport = Self { reader, writer, + stderr, incoming, outgoing, pending_requests: Default::default(), |