From ebfd67ac6ab0e0b10b99dec2d5fc7bb42d8fb10b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Tue, 30 Mar 2021 16:39:24 +0900 Subject: [PATCH] Use StreamExt::select_next_some to avoid infinitely spinning on empty stream. --- helix-term/src/application.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index b7f88aaa..2a813081 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -99,10 +99,10 @@ impl Application { event = reader.next().fuse() => { self.handle_terminal_events(event) } - call = self.editor.language_servers.incoming.next().fuse() => { + call = futures_util::StreamExt::select_next_some(&mut self.editor.language_servers.incoming) => { self.handle_language_server_message(call).await } - callback = self.callbacks.next().fuse() => { + callback = futures_util::StreamExt::select_next_some(&mut self.callbacks) => { self.handle_language_server_callback(callback) } } @@ -110,9 +110,9 @@ impl Application { } pub fn handle_language_server_callback( &mut self, - callback: Option>, + callback: Result, ) { - if let Some(Ok(callback)) = callback { + if let Ok(callback) = callback { // TODO: handle Err() callback(&mut self.editor, &mut self.compositor); self.render(); @@ -144,12 +144,10 @@ impl Application { } } - pub async fn handle_language_server_message(&mut self, call: Option) { + pub async fn handle_language_server_message(&mut self, call: helix_lsp::Call) { use helix_lsp::{Call, Notification}; match call { - Some(Call::Notification(helix_lsp::jsonrpc::Notification { - method, params, .. - })) => { + Call::Notification(helix_lsp::jsonrpc::Notification { method, params, .. }) => { let notification = Notification::parse(&method, params); match notification { Notification::PublishDiagnostics(params) => { @@ -203,7 +201,7 @@ impl Application { _ => unreachable!(), } } - Some(Call::MethodCall(call)) => { + Call::MethodCall(call) => { error!("Method not found {}", call.method); // self.language_server.reply( @@ -216,7 +214,6 @@ impl Application { // }), // ); } - None => (), e => unreachable!("{:?}", e), } }