diff options
author | Blaž Hrastnik | 2020-10-23 09:48:03 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-12-03 04:10:35 +0000 |
commit | cc6bdf8f66889087223d9a8491479ceecc09a663 (patch) | |
tree | a155b55868052007d3530327de087886a7d81b7f /helix-term/src | |
parent | af1924404adac399c351a17bc0f43b5e2889abbb (diff) |
Text change generation, RPC call handling.
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/application.rs | 87 |
1 files changed, 50 insertions, 37 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index b9594b7e..802dd399 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -433,8 +433,8 @@ impl<'a> Application<'a> { event = reader.next().fuse() => { self.handle_terminal_events(event).await } - notification = self.lsp.incoming.next().fuse() => { - self.handle_lsp_notification(notification).await + call = self.lsp.incoming.next().fuse() => { + self.handle_lsp_message(call).await } } } @@ -566,43 +566,56 @@ impl<'a> Application<'a> { }; } - pub async fn handle_lsp_notification(&mut self, notification: Option<helix_lsp::Notification>) { - use helix_lsp::Notification; - match notification { - Some(Notification::PublishDiagnostics(params)) => { - let path = Some(params.uri.to_file_path().unwrap()); - let view = self - .editor - .views - .iter_mut() - .find(|view| view.doc.path == path); - - if let Some(view) = view { - let doc = view.doc.text().slice(..); - let diagnostics = params - .diagnostics - .into_iter() - .map(|diagnostic| { - use helix_lsp::util::lsp_pos_to_pos; - let start = lsp_pos_to_pos(&doc, diagnostic.range.start); - let end = lsp_pos_to_pos(&doc, diagnostic.range.end); - - helix_core::Diagnostic { - range: (start, end), - line: diagnostic.range.start.line as usize, - message: diagnostic.message, - // severity - // code - // source - } - }) - .collect(); - - view.doc.diagnostics = diagnostics; - - self.render(); + pub async fn handle_lsp_message(&mut self, call: Option<helix_lsp::Call>) { + use helix_lsp::{Call, Notification}; + match call { + Some(Call::Notification(helix_lsp::jsonrpc::Notification { + method, params, .. + })) => { + let notification = Notification::parse(&method, params); + match notification { + Notification::PublishDiagnostics(params) => { + let path = Some(params.uri.to_file_path().unwrap()); + let view = self + .editor + .views + .iter_mut() + .find(|view| view.doc.path == path); + + if let Some(view) = view { + let doc = view.doc.text().slice(..); + let diagnostics = params + .diagnostics + .into_iter() + .map(|diagnostic| { + use helix_lsp::util::lsp_pos_to_pos; + let start = lsp_pos_to_pos(&doc, diagnostic.range.start); + let end = lsp_pos_to_pos(&doc, diagnostic.range.end); + + helix_core::Diagnostic { + range: (start, end), + line: diagnostic.range.start.line as usize, + message: diagnostic.message, + // severity + // code + // source + } + }) + .collect(); + + view.doc.diagnostics = diagnostics; + + self.render(); + } + } + _ => unreachable!(), } } + Some(Call::MethodCall(call)) => { + // TODO: need to make Result<Value, Error> + + unimplemented!("{:?}", call) + } _ => unreachable!(), } } |