Reduce spamming of inline completion discard events (#11999)

I'm not a huge fan of passing around a boolean all around the place, but
this will tame the events for now until we have a better solution.

Release Notes:

- N/A
This commit is contained in:
Joseph T. Lyons 2024-05-17 16:37:17 -04:00 committed by GitHub
parent 99c6389ff8
commit e5a4421559
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 57 additions and 42 deletions

View File

@ -22,7 +22,6 @@ pub struct CopilotCompletionProvider {
pending_cycling_refresh: Task<Result<()>>, pending_cycling_refresh: Task<Result<()>>,
copilot: Model<Copilot>, copilot: Model<Copilot>,
telemetry: Option<Arc<Telemetry>>, telemetry: Option<Arc<Telemetry>>,
should_allow_event_to_send: bool,
} }
impl CopilotCompletionProvider { impl CopilotCompletionProvider {
@ -37,7 +36,6 @@ impl CopilotCompletionProvider {
pending_cycling_refresh: Task::ready(Ok(())), pending_cycling_refresh: Task::ready(Ok(())),
copilot, copilot,
telemetry: None, telemetry: None,
should_allow_event_to_send: false,
} }
} }
@ -105,7 +103,6 @@ impl InlineCompletionProvider for CopilotCompletionProvider {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
if !completions.is_empty() { if !completions.is_empty() {
this.should_allow_event_to_send = true;
this.cycled = false; this.cycled = false;
this.pending_cycling_refresh = Task::ready(Ok(())); this.pending_cycling_refresh = Task::ready(Ok(()));
this.completions.clear(); this.completions.clear();
@ -193,8 +190,8 @@ impl InlineCompletionProvider for CopilotCompletionProvider {
self.copilot self.copilot
.update(cx, |copilot, cx| copilot.accept_completion(completion, cx)) .update(cx, |copilot, cx| copilot.accept_completion(completion, cx))
.detach_and_log_err(cx); .detach_and_log_err(cx);
if let Some(telemetry) = self.telemetry.as_ref() { if self.active_completion().is_some() {
if self.should_allow_event_to_send { if let Some(telemetry) = self.telemetry.as_ref() {
telemetry.report_inline_completion_event( telemetry.report_inline_completion_event(
Self::name().to_string(), Self::name().to_string(),
true, true,
@ -203,11 +200,13 @@ impl InlineCompletionProvider for CopilotCompletionProvider {
} }
} }
} }
self.should_allow_event_to_send = false;
} }
fn discard(&mut self, cx: &mut ModelContext<Self>) { fn discard(
&mut self,
should_report_inline_completion_event: bool,
cx: &mut ModelContext<Self>,
) {
let settings = AllLanguageSettings::get_global(cx); let settings = AllLanguageSettings::get_global(cx);
let copilot_enabled = settings.inline_completions_enabled(None, None); let copilot_enabled = settings.inline_completions_enabled(None, None);
@ -222,17 +221,17 @@ impl InlineCompletionProvider for CopilotCompletionProvider {
}) })
.detach_and_log_err(cx); .detach_and_log_err(cx);
if let Some(telemetry) = self.telemetry.as_ref() { if should_report_inline_completion_event {
if self.should_allow_event_to_send { if self.active_completion().is_some() {
telemetry.report_inline_completion_event( if let Some(telemetry) = self.telemetry.as_ref() {
Self::name().to_string(), telemetry.report_inline_completion_event(
false, Self::name().to_string(),
self.file_extension.clone(), false,
); self.file_extension.clone(),
);
}
} }
} }
self.should_allow_event_to_send = false;
} }
fn active_completion_text<'a>( fn active_completion_text<'a>(

View File

@ -2161,7 +2161,7 @@ impl Editor {
self.refresh_code_actions(cx); self.refresh_code_actions(cx);
self.refresh_document_highlights(cx); self.refresh_document_highlights(cx);
refresh_matching_bracket_highlights(self, cx); refresh_matching_bracket_highlights(self, cx);
self.discard_inline_completion(cx); self.discard_inline_completion(false, cx);
if self.git_blame_inline_enabled { if self.git_blame_inline_enabled {
self.start_inline_blame_timer(cx); self.start_inline_blame_timer(cx);
} }
@ -2566,7 +2566,7 @@ impl Editor {
pub fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) { pub fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
self.clear_expanded_diff_hunks(cx); self.clear_expanded_diff_hunks(cx);
if self.dismiss_menus_and_popups(cx) { if self.dismiss_menus_and_popups(true, cx) {
return; return;
} }
@ -2579,7 +2579,11 @@ impl Editor {
cx.propagate(); cx.propagate();
} }
pub fn dismiss_menus_and_popups(&mut self, cx: &mut ViewContext<Self>) -> bool { pub fn dismiss_menus_and_popups(
&mut self,
should_report_inline_completion_event: bool,
cx: &mut ViewContext<Self>,
) -> bool {
if self.take_rename(false, cx).is_some() { if self.take_rename(false, cx).is_some() {
return true; return true;
} }
@ -2592,7 +2596,7 @@ impl Editor {
return true; return true;
} }
if self.discard_inline_completion(cx) { if self.discard_inline_completion(should_report_inline_completion_event, cx) {
return true; return true;
} }
@ -3704,7 +3708,7 @@ impl Editor {
let menu = menu.unwrap(); let menu = menu.unwrap();
*context_menu = Some(ContextMenu::Completions(menu)); *context_menu = Some(ContextMenu::Completions(menu));
drop(context_menu); drop(context_menu);
this.discard_inline_completion(cx); this.discard_inline_completion(false, cx);
cx.notify(); cx.notify();
} else if this.completion_tasks.len() <= 1 { } else if this.completion_tasks.len() <= 1 {
// If there are no more completion tasks and the last menu was // If there are no more completion tasks and the last menu was
@ -3918,7 +3922,7 @@ impl Editor {
} }
this.completion_tasks.clear(); this.completion_tasks.clear();
this.discard_inline_completion(cx); this.discard_inline_completion(false, cx);
let task_context = tasks.as_ref().zip(this.workspace.clone()).and_then( let task_context = tasks.as_ref().zip(this.workspace.clone()).and_then(
|(tasks, (workspace, _))| { |(tasks, (workspace, _))| {
let position = Point::new(buffer_row, tasks.1.column); let position = Point::new(buffer_row, tasks.1.column);
@ -4313,7 +4317,7 @@ impl Editor {
if !self.show_inline_completions if !self.show_inline_completions
|| !provider.is_enabled(&buffer, cursor_buffer_position, cx) || !provider.is_enabled(&buffer, cursor_buffer_position, cx)
{ {
self.discard_inline_completion(cx); self.discard_inline_completion(false, cx);
return None; return None;
} }
@ -4448,9 +4452,13 @@ impl Editor {
} }
} }
fn discard_inline_completion(&mut self, cx: &mut ViewContext<Self>) -> bool { fn discard_inline_completion(
&mut self,
should_report_inline_completion_event: bool,
cx: &mut ViewContext<Self>,
) -> bool {
if let Some(provider) = self.inline_completion_provider() { if let Some(provider) = self.inline_completion_provider() {
provider.discard(cx); provider.discard(should_report_inline_completion_event, cx);
} }
self.take_active_inline_completion(cx).is_some() self.take_active_inline_completion(cx).is_some()
@ -4513,7 +4521,7 @@ impl Editor {
} }
} }
self.discard_inline_completion(cx); self.discard_inline_completion(false, cx);
} }
fn inline_completion_provider(&self) -> Option<Arc<dyn InlineCompletionProviderHandle>> { fn inline_completion_provider(&self) -> Option<Arc<dyn InlineCompletionProviderHandle>> {

View File

@ -25,7 +25,7 @@ pub trait InlineCompletionProvider: 'static + Sized {
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
); );
fn accept(&mut self, cx: &mut ModelContext<Self>); fn accept(&mut self, cx: &mut ModelContext<Self>);
fn discard(&mut self, cx: &mut ModelContext<Self>); fn discard(&mut self, should_report_inline_completion_event: bool, cx: &mut ModelContext<Self>);
fn active_completion_text<'a>( fn active_completion_text<'a>(
&'a self, &'a self,
buffer: &Model<Buffer>, buffer: &Model<Buffer>,
@ -56,7 +56,7 @@ pub trait InlineCompletionProviderHandle {
cx: &mut AppContext, cx: &mut AppContext,
); );
fn accept(&self, cx: &mut AppContext); fn accept(&self, cx: &mut AppContext);
fn discard(&self, cx: &mut AppContext); fn discard(&self, should_report_inline_completion_event: bool, cx: &mut AppContext);
fn active_completion_text<'a>( fn active_completion_text<'a>(
&'a self, &'a self,
buffer: &Model<Buffer>, buffer: &Model<Buffer>,
@ -106,8 +106,10 @@ where
self.update(cx, |this, cx| this.accept(cx)) self.update(cx, |this, cx| this.accept(cx))
} }
fn discard(&self, cx: &mut AppContext) { fn discard(&self, should_report_inline_completion_event: bool, cx: &mut AppContext) {
self.update(cx, |this, cx| this.discard(cx)) self.update(cx, |this, cx| {
this.discard(should_report_inline_completion_event, cx)
})
} }
fn active_completion_text<'a>( fn active_completion_text<'a>(

View File

@ -100,8 +100,8 @@ impl InlineCompletionProvider for SupermavenCompletionProvider {
} }
fn accept(&mut self, _cx: &mut ModelContext<Self>) { fn accept(&mut self, _cx: &mut ModelContext<Self>) {
if let Some(telemetry) = self.telemetry.as_ref() { if self.completion_id.is_some() {
if let Some(_) = self.completion_id { if let Some(telemetry) = self.telemetry.as_ref() {
telemetry.report_inline_completion_event( telemetry.report_inline_completion_event(
Self::name().to_string(), Self::name().to_string(),
true, true,
@ -113,14 +113,20 @@ impl InlineCompletionProvider for SupermavenCompletionProvider {
self.completion_id = None; self.completion_id = None;
} }
fn discard(&mut self, _cx: &mut ModelContext<Self>) { fn discard(
if let Some(telemetry) = self.telemetry.as_ref() { &mut self,
if let Some(_) = self.completion_id { should_report_inline_completion_event: bool,
telemetry.report_inline_completion_event( _cx: &mut ModelContext<Self>,
Self::name().to_string(), ) {
false, if should_report_inline_completion_event {
self.file_extension.clone(), if self.completion_id.is_some() {
); if let Some(telemetry) = self.telemetry.as_ref() {
telemetry.report_inline_completion_event(
Self::name().to_string(),
false,
self.file_extension.clone(),
);
}
} }
} }

View File

@ -16,7 +16,7 @@ fn normal_before(_: &mut Workspace, action: &NormalBefore, cx: &mut ViewContext<
vim.stop_recording_immediately(action.boxed_clone()); vim.stop_recording_immediately(action.boxed_clone());
if count <= 1 || vim.workspace_state.replaying { if count <= 1 || vim.workspace_state.replaying {
vim.update_active_editor(cx, |_, editor, cx| { vim.update_active_editor(cx, |_, editor, cx| {
editor.dismiss_menus_and_popups(cx); editor.dismiss_menus_and_popups(false, cx);
editor.change_selections(Some(Autoscroll::fit()), cx, |s| { editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.move_cursors_with(|map, mut cursor, _| { s.move_cursors_with(|map, mut cursor, _| {
*cursor.column_mut() = cursor.column().saturating_sub(1); *cursor.column_mut() = cursor.column().saturating_sub(1);