Fixed panic in new cycling code

Made cycling fire without debounce
This commit is contained in:
Mikayla Maki 2023-04-19 16:50:31 -07:00
parent 2882e0fa5b
commit 9b8a3e4de5
2 changed files with 23 additions and 26 deletions

View file

@ -5,7 +5,7 @@ use gpui::{
platform::{WindowBounds, WindowKind, WindowOptions}, platform::{WindowBounds, WindowKind, WindowOptions},
AppContext, ClipboardItem, Element, Entity, View, ViewContext, ViewHandle, AppContext, ClipboardItem, Element, Entity, View, ViewContext, ViewHandle,
}; };
use settings::{settings_file::SettingsFile, Settings}; use settings::Settings;
use theme::ui::modal; use theme::ui::modal;
#[derive(PartialEq, Eq, Debug, Clone)] #[derive(PartialEq, Eq, Debug, Clone)]

View file

@ -1083,8 +1083,12 @@ impl CopilotState {
}; };
} }
Direction::Next => { Direction::Next => {
self.active_completion_index = if self.completions.len() == 0 {
(self.active_completion_index + 1) % self.completions.len(); self.active_completion_index = 0
} else {
self.active_completion_index =
(self.active_completion_index + 1) % self.completions.len();
}
} }
} }
} }
@ -2850,22 +2854,15 @@ impl Editor {
self.copilot_state.pending_refresh = cx.spawn_weak(|this, mut cx| async move { self.copilot_state.pending_refresh = cx.spawn_weak(|this, mut cx| async move {
cx.background().timer(COPILOT_DEBOUNCE_TIMEOUT).await; cx.background().timer(COPILOT_DEBOUNCE_TIMEOUT).await;
let mut completions = Vec::new(); let completions = copilot
// let completions_iter = if cycling {
let completions_iter = copilot
.update(&mut cx, |copilot, cx| { .update(&mut cx, |copilot, cx| {
copilot.completions(&buffer, buffer_position, cx) copilot.completions(&buffer, buffer_position, cx)
}) })
.await; .await
// } else { .log_err()
// copilot .into_iter()
// .update(&mut cx, |copilot, cx| { .flatten()
// copilot.completions_cycling(&buffer, buffer_position, cx) .collect_vec();
// })
// .await
// };
completions.extend(completions_iter.log_err().into_iter().flatten());
this.upgrade(&cx)?.update(&mut cx, |this, cx| { this.upgrade(&cx)?.update(&mut cx, |this, cx| {
if !completions.is_empty() { if !completions.is_empty() {
@ -2937,11 +2934,11 @@ impl Editor {
} }
fn next_copilot_suggestion(&mut self, _: &copilot::NextSuggestion, cx: &mut ViewContext<Self>) { fn next_copilot_suggestion(&mut self, _: &copilot::NextSuggestion, cx: &mut ViewContext<Self>) {
if self.has_active_copilot_suggestion(cx) { // if self.has_active_copilot_suggestion(cx) {
self.cycle_suggestions(Direction::Next, cx); self.cycle_suggestions(Direction::Next, cx);
} else { // } else {
self.refresh_copilot_suggestions(cx); // self.refresh_copilot_suggestions(cx);
} // }
} }
fn previous_copilot_suggestion( fn previous_copilot_suggestion(
@ -2949,11 +2946,11 @@ impl Editor {
_: &copilot::PreviousSuggestion, _: &copilot::PreviousSuggestion,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
if self.has_active_copilot_suggestion(cx) { // if self.has_active_copilot_suggestion(cx) {
self.cycle_suggestions(Direction::Prev, cx); self.cycle_suggestions(Direction::Prev, cx);
} else { // } else {
self.refresh_copilot_suggestions(cx); // self.refresh_copilot_suggestions(cx);
} // }
} }
fn accept_copilot_suggestion(&mut self, cx: &mut ViewContext<Self>) -> bool { fn accept_copilot_suggestion(&mut self, cx: &mut ViewContext<Self>) -> bool {