From 6f0f9d631e14031a25bf3e48a6105dacda3165f5 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 4 Feb 2025 12:49:08 -0800 Subject: [PATCH] Allow running cancel-language-server-work action w/o editor focused (#24215) Release Notes: - Added the ability to run the `cancel language server work` action while a panel (like the terminal panel) is focused --- crates/editor/src/editor.rs | 22 +++++++++++++--------- crates/editor/src/element.rs | 1 - 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 63f0068eda..05337a0f5a 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -306,6 +306,7 @@ pub fn init(cx: &mut App) { workspace.register_action(Editor::new_file); workspace.register_action(Editor::new_file_vertical); workspace.register_action(Editor::new_file_horizontal); + workspace.register_action(Editor::cancel_language_server_work); }, ) .detach(); @@ -11306,18 +11307,21 @@ impl Editor { } fn cancel_language_server_work( - &mut self, + workspace: &mut Workspace, _: &actions::CancelLanguageServerWork, _: &mut Window, - cx: &mut Context, + cx: &mut Context, ) { - if let Some(project) = self.project.clone() { - self.buffer.update(cx, |multi_buffer, cx| { - project.update(cx, |project, cx| { - project.cancel_language_server_work_for_buffers(multi_buffer.all_buffers(), cx); - }); - }) - } + let project = workspace.project(); + let buffers = workspace + .active_item(cx) + .and_then(|item| item.act_as::(cx)) + .map_or(HashSet::default(), |editor| { + editor.read(cx).buffer.read(cx).all_buffers() + }); + project.update(cx, |project, cx| { + project.cancel_language_server_work_for_buffers(buffers, cx); + }); } fn show_character_palette( diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 632c81c6b1..af6339cd68 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -430,7 +430,6 @@ impl EditorElement { } }); register_action(editor, window, Editor::restart_language_server); - register_action(editor, window, Editor::cancel_language_server_work); register_action(editor, window, Editor::show_character_palette); register_action(editor, window, |editor, action, window, cx| { if let Some(task) = editor.confirm_completion(action, window, cx) {