aboutsummaryrefslogtreecommitdiff
path: root/helix-lsp/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-10-20 04:58:34 +0000
committerBlaž Hrastnik2020-12-03 04:10:32 +0000
commitf9bfba4d96f80eb41beb91702558f6f165a0e70f (patch)
treee2e0296a01645cdcb7782a9bd8b4f1a55d3fbfd9 /helix-lsp/src
parent64b5b23315f12125a2c5b2f810fe5ac285bdfa79 (diff)
Reroute LSP notification events into the main app event loop.
Diffstat (limited to 'helix-lsp/src')
-rw-r--r--helix-lsp/src/lib.rs33
-rw-r--r--helix-lsp/src/transport.rs14
2 files changed, 23 insertions, 24 deletions
diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs
index 41b3fdb2..3598a594 100644
--- a/helix-lsp/src/lib.rs
+++ b/helix-lsp/src/lib.rs
@@ -2,7 +2,7 @@ mod transport;
use transport::{Payload, Transport};
-use std::collections::HashMap;
+// use std::collections::HashMap;
use jsonrpc_core as jsonrpc;
use lsp_types as lsp;
@@ -32,10 +32,12 @@ enum Message {
}
#[derive(Debug, PartialEq, Clone)]
-enum Notification {}
+pub enum Notification {
+ PublishDiagnostics(lsp::PublishDiagnosticsParams),
+}
impl Notification {
- pub fn parse(method: &str, params: jsonrpc::Params) {
+ pub fn parse(method: &str, params: jsonrpc::Params) -> Notification {
use lsp::notification::Notification as _;
match method {
@@ -44,11 +46,10 @@ impl Notification {
.parse()
.expect("Failed to parse PublishDiagnostics params");
- println!("{:?}", params);
-
// TODO: need to loop over diagnostics and distinguish them by URI
+ Notification::PublishDiagnostics(params)
}
- _ => println!("unhandled notification: {}", method),
+ _ => unimplemented!("unhandled notification: {}", method),
}
}
}
@@ -58,13 +59,13 @@ pub struct Client {
stderr: BufReader<ChildStderr>,
outgoing: Sender<Payload>,
- incoming: Receiver<Message>,
+ pub incoming: Receiver<Notification>,
pub request_counter: u64,
capabilities: Option<lsp::ServerCapabilities>,
// TODO: handle PublishDiagnostics Version
- diagnostics: HashMap<lsp::Url, Vec<lsp::Diagnostic>>,
+ // diagnostics: HashMap<lsp::Url, Vec<lsp::Diagnostic>>,
}
impl Client {
@@ -95,7 +96,7 @@ impl Client {
request_counter: 0,
capabilities: None,
- diagnostics: HashMap::new(),
+ // diagnostics: HashMap::new(),
}
}
@@ -226,10 +227,7 @@ impl Client {
) -> anyhow::Result<()> {
self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
text_document: lsp::TextDocumentItem {
- uri: lsp::Url::from_file_path(
- std::fs::canonicalize(state.path.as_ref().unwrap()).unwrap(),
- )
- .unwrap(),
+ uri: lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
language_id: "rust".to_string(), // TODO: hardcoded for now
version: 0,
text: String::from(&state.doc),
@@ -243,11 +241,12 @@ impl Client {
&mut self,
state: &helix_core::State,
) -> anyhow::Result<()> {
- self.notify::<lsp::notification::DidSaveTextDocument>(lsp::DidSaveTextDocumentParams {
- text_document: lsp::TextDocumentIdentifier::new(
- lsp::Url::from_file_path(state.path.as_ref().unwrap()).unwrap(),
+ self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
+ text_document: lsp::VersionedTextDocumentIdentifier::new(
+ lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
+ 0, // TODO: version
),
- text: None, // TODO?
+ content_changes: vec![], // TODO:
})
.await
}
diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs
index c44ffa91..8915a925 100644
--- a/helix-lsp/src/transport.rs
+++ b/helix-lsp/src/transport.rs
@@ -24,7 +24,7 @@ pub(crate) enum Payload {
}
pub(crate) struct Transport {
- incoming: Sender<Message>,
+ incoming: Sender<Notification>, // TODO Notification | Call
outgoing: Receiver<Payload>,
pending_requests: HashMap<jsonrpc::Id, Sender<anyhow::Result<Value>>>,
@@ -39,7 +39,7 @@ impl Transport {
ex: &Executor,
reader: BufReader<ChildStdout>,
writer: BufWriter<ChildStdin>,
- ) -> (Receiver<Message>, Sender<Payload>) {
+ ) -> (Receiver<Notification>, Sender<Payload>) {
let (incoming, rx) = smol::channel::unbounded();
let (tx, outgoing) = smol::channel::unbounded();
@@ -111,7 +111,7 @@ impl Transport {
}
pub async fn send(&mut self, request: String) -> anyhow::Result<()> {
- println!("-> {}", request);
+ // println!("-> {}", request);
// send the headers
self.writer
@@ -132,11 +132,11 @@ impl Transport {
Message::Notification(jsonrpc::Notification { method, params, .. }) => {
let notification = Notification::parse(&method, params);
- println!("<- {} {:?}", method, notification);
- // dispatch
+ // println!("<- {} {:?}", method, notification);
+ self.incoming.send(notification).await?;
}
Message::Call(call) => {
- println!("<- {:?}", call);
+ // println!("<- {:?}", call);
// dispatch
}
_ => unreachable!(),
@@ -147,7 +147,7 @@ impl Transport {
pub async fn recv_response(&mut self, output: jsonrpc::Output) -> anyhow::Result<()> {
match output {
jsonrpc::Output::Success(jsonrpc::Success { id, result, .. }) => {
- println!("<- {}", result);
+ // println!("<- {}", result);
let tx = self
.pending_requests