Remove per-file copilot enable/disable
This commit is contained in:
parent
0250898a2b
commit
48d9c30b0e
4 changed files with 14 additions and 90 deletions
|
@ -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<Option<()>>,
|
||||
completions: Vec<copilot::Completion>,
|
||||
active_completion_index: usize,
|
||||
pub user_enabled: Option<bool>,
|
||||
}
|
||||
|
||||
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::<Settings>();
|
||||
|
||||
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::<Settings>().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<Self>) {
|
||||
// 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<Self>,
|
||||
) {
|
||||
// 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>) {
|
||||
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::<Settings>().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<Self>) {
|
||||
let snapshot = self.buffer.read(cx).snapshot(cx);
|
||||
let cursor = self.selections.newest_anchor().head();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue