on master help sign in
Prevent LSP Messages from displaying when a prompt is presented (#824)

* Prevent LSP Messages from displaying when a prompt is presented * use match guard

commit4d07eaa48bc4fc0c75e0346406fb6dedfc7db743 authorLeoi Hung Kin <leoihungkin@outlook.com> dateFri 15 Oct 2021, 16:36 (5 years ago) parentef3f78b
2 files changed+30−9
helix-term/src/application.rs+24−9 helix-term/src/compositor.rs+6
helix-term/src/application.rs+24−9
@@ -295,14 +295,6 @@ impl Application {
295295 server_id: usize,
296296 ) {
297297 use helix_lsp::{Call, MethodCall, Notification};
298− let editor_view = self
299− .compositor
300− .find(std::any::type_name::<ui::EditorView>())
301− .expect("expected at least one EditorView");
302− let editor_view = editor_view
303− .as_any_mut()
304− .downcast_mut::<ui::EditorView>()
305− .unwrap();
306298
307299 match call {
308300 Call::Notification(helix_lsp::jsonrpc::Notification { method, params, .. }) => {
@@ -412,7 +404,19 @@ impl Application {
412404 Notification::LogMessage(params) => {
413405 log::info!("window/logMessage: {:?}", params);
414406 }
415− Notification::ProgressMessage(params) => {
407+ Notification::ProgressMessage(params)
408+ if !self
409+ .compositor
410+ .has_component(std::any::type_name::<ui::Prompt>()) =>
411+ {
412+ let editor_view = self
413+ .compositor
414+ .find(std::any::type_name::<ui::EditorView>())
415+ .expect("expected at least one EditorView");
416+ let editor_view = editor_view
417+ .as_any_mut()
418+ .downcast_mut::<ui::EditorView>()
419+ .unwrap();
416420 let lsp::ProgressParams { token, value } = params;
417421
418422 let lsp::ProgressParamsValue::WorkDone(work) = value;
@@ -487,6 +491,9 @@ impl Application {
487491 self.editor.set_status(status);
488492 }
489493 }
494+ Notification::ProgressMessage(_params) => {
495+ // do nothing
496+ }
490497 }
491498 }
492499 Call::MethodCall(helix_lsp::jsonrpc::MethodCall {
@@ -521,6 +528,14 @@ impl Application {
521528 MethodCall::WorkDoneProgressCreate(params) => {
522529 self.lsp_progress.create(server_id, params.token);
523530
531+ let editor_view = self
532+ .compositor
533+ .find(std::any::type_name::<ui::EditorView>())
534+ .expect("expected at least one EditorView");
535+ let editor_view = editor_view
536+ .as_any_mut()
537+ .downcast_mut::<ui::EditorView>()
538+ .unwrap();
524539 let spinner = editor_view.spinners_mut().get_or_create(server_id);
525540 if spinner.is_stopped() {
526541 spinner.start();
helix-term/src/compositor.rs+6
@@ -171,6 +171,12 @@ impl Compositor {
171171 (None, CursorKind::Hidden)
172172 }
173173
174+ pub fn has_component(&self, type_name: &str) -> bool {
175+ self.layers
176+ .iter()
177+ .any(|component| component.type_name() == type_name)
178+ }
179+
174180 pub fn find(&mut self, type_name: &str) -> Option<&mut dyn Component> {
175181 self.layers
176182 .iter_mut()