From 48d9c30b0efa648c3905fbe186d19de47aee6d47 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 3 Apr 2023 15:15:42 -0700 Subject: [PATCH] Remove per-file copilot enable/disable --- assets/keymaps/default.json | 3 +- crates/copilot/src/copilot.rs | 5 +- crates/copilot_button/src/copilot_button.rs | 19 +---- crates/editor/src/editor.rs | 77 +++------------------ 4 files changed, 14 insertions(+), 90 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 1a8350bb53..f5446462e6 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -178,8 +178,7 @@ } ], "alt-]": "copilot::NextSuggestion", - "alt-[": "copilot::PreviousSuggestion", - "alt-\\": "copilot::Toggle" + "alt-[": "copilot::PreviousSuggestion" } }, { diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index 1fb7ee0b5b..0a7851bb0d 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -32,10 +32,7 @@ const COPILOT_AUTH_NAMESPACE: &'static str = "copilot_auth"; actions!(copilot_auth, [SignIn, SignOut]); const COPILOT_NAMESPACE: &'static str = "copilot"; -actions!( - copilot, - [NextSuggestion, PreviousSuggestion, Toggle, Reinstall] -); +actions!(copilot, [NextSuggestion, PreviousSuggestion, Reinstall]); pub fn init(client: Arc, node_runtime: Arc, cx: &mut MutableAppContext) { let copilot = cx.add_model(|cx| Copilot::start(client.http_client(), node_runtime, cx)); diff --git a/crates/copilot_button/src/copilot_button.rs b/crates/copilot_button/src/copilot_button.rs index ebb09701f6..62305553a3 100644 --- a/crates/copilot_button/src/copilot_button.rs +++ b/crates/copilot_button/src/copilot_button.rs @@ -249,19 +249,6 @@ impl CopilotButton { let mut menu_options = Vec::with_capacity(6); - if let Some((_, view_id)) = self.editor_subscription.as_ref() { - let locally_enabled = self.editor_enabled.unwrap_or(settings.copilot_on(None)); - menu_options.push(ContextMenuItem::item_for_view( - if locally_enabled { - "Pause Copilot for this file" - } else { - "Resume Copilot for this file" - }, - *view_id, - copilot::Toggle, - )); - } - if let Some(language) = &self.language { let language_enabled = settings.copilot_on(Some(language.as_ref())); @@ -334,11 +321,7 @@ impl CopilotButton { self.language = language_name.clone(); - if let Some(enabled) = editor.copilot_state.user_enabled { - self.editor_enabled = Some(enabled); - } else { - self.editor_enabled = Some(settings.copilot_on(language_name.as_deref())); - } + self.editor_enabled = Some(settings.copilot_on(language_name.as_deref())); cx.notify() } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 067b06bd6e..cf7ff144a4 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -391,7 +391,6 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_async_action(Editor::find_all_references); cx.add_action(Editor::next_copilot_suggestion); cx.add_action(Editor::previous_copilot_suggestion); - cx.add_action(Editor::toggle_copilot_suggestions); hover_popover::init(cx); link_go_to_definition::init(cx); @@ -1013,7 +1012,6 @@ pub struct CopilotState { pending_refresh: Task>, completions: Vec, active_completion_index: usize, - pub user_enabled: Option, } impl Default for CopilotState { @@ -1023,7 +1021,6 @@ impl Default for CopilotState { pending_refresh: Task::ready(Some(())), completions: Default::default(), active_completion_index: 0, - user_enabled: None, } } } @@ -2780,37 +2777,24 @@ impl Editor { return None; } - let settings = cx.global::(); - - if !self - .copilot_state - .user_enabled - .unwrap_or_else(|| settings.copilot_on(None)) - { - return None; - } - - let snapshot = self.buffer.read(cx).snapshot(cx); let selection = self.selections.newest_anchor(); - - if !self.copilot_state.user_enabled.is_some() { - let language_name = snapshot - .language_at(selection.start) - .map(|language| language.name()); - - let copilot_enabled = settings.copilot_on(language_name.as_deref()); - - if !copilot_enabled { - return None; - } - } + let snapshot = self.buffer.read(cx).snapshot(cx); let cursor = if selection.start == selection.end { selection.start.bias_left(&snapshot) } else { return None; }; - self.refresh_active_copilot_suggestion(cx); + + let language_name = snapshot + .language_at(selection.start) + .map(|language| language.name()); + + let copilot_enabled = cx.global::().copilot_on(language_name.as_deref()); + + if !copilot_enabled { + return None; + } if !copilot.read(cx).status().is_authorized() { return None; @@ -2849,12 +2833,6 @@ impl Editor { } fn next_copilot_suggestion(&mut self, _: &copilot::NextSuggestion, cx: &mut ViewContext) { - // Auto re-enable copilot if you're asking for a suggestion - if self.copilot_state.user_enabled == Some(false) { - cx.notify(); - self.copilot_state.user_enabled = Some(true); - } - if self.copilot_state.completions.is_empty() { self.refresh_copilot_suggestions(cx); return; @@ -2871,12 +2849,6 @@ impl Editor { _: &copilot::PreviousSuggestion, cx: &mut ViewContext, ) { - // Auto re-enable copilot if you're asking for a suggestion - if self.copilot_state.user_enabled == Some(false) { - cx.notify(); - self.copilot_state.user_enabled = Some(true); - } - if self.copilot_state.completions.is_empty() { self.refresh_copilot_suggestions(cx); return; @@ -2892,33 +2864,6 @@ impl Editor { self.refresh_active_copilot_suggestion(cx); } - fn toggle_copilot_suggestions(&mut self, _: &copilot::Toggle, cx: &mut ViewContext) { - self.copilot_state.user_enabled = match self.copilot_state.user_enabled { - Some(enabled) => Some(!enabled), - None => { - let selection = self.selections.newest_anchor().start; - - let language_name = self - .snapshot(cx) - .language_at(selection) - .map(|language| language.name()); - - let copilot_enabled = cx.global::().copilot_on(language_name.as_deref()); - - Some(!copilot_enabled) - } - }; - - // We know this can't be None, as we just set it to Some above - if self.copilot_state.user_enabled == Some(true) { - self.refresh_copilot_suggestions(cx); - } else { - self.clear_copilot_suggestions(cx); - } - - cx.notify(); - } - fn refresh_active_copilot_suggestion(&mut self, cx: &mut ViewContext) { let snapshot = self.buffer.read(cx).snapshot(cx); let cursor = self.selections.newest_anchor().head();