mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
Remove per-file copilot enable/disable
This commit is contained in:
parent
0250898a2b
commit
48d9c30b0e
@ -178,8 +178,7 @@
|
||||
}
|
||||
],
|
||||
"alt-]": "copilot::NextSuggestion",
|
||||
"alt-[": "copilot::PreviousSuggestion",
|
||||
"alt-\\": "copilot::Toggle"
|
||||
"alt-[": "copilot::PreviousSuggestion"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -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<Client>, node_runtime: Arc<NodeRuntime>, cx: &mut MutableAppContext) {
|
||||
let copilot = cx.add_model(|cx| Copilot::start(client.http_client(), node_runtime, cx));
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user