Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/cloud_llm_client/src/cloud_llm_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ pub struct PredictEditsBody {
pub enum PredictEditsRequestTrigger {
Testing,
Diagnostics,
DiagnosticNavigation,
Cli,
Explicit,
BufferEdit,
LSPCompletionAccepted,
PredictionAccepted,
PredictionPartiallyAccepted,
#[default]
Other,
}
Expand Down
2 changes: 2 additions & 0 deletions crates/codestral/src/codestral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Result;
use edit_prediction::cursor_excerpt;
use edit_prediction_types::{
EditPrediction, EditPredictionDelegate, EditPredictionDiscardReason, EditPredictionIconSet,
EditPredictionRequestTrigger,
};
use futures::AsyncReadExt;
use gpui::{App, AppContext as _, Context, Entity, Global, SharedString, Task};
Expand Down Expand Up @@ -222,6 +223,7 @@ impl EditPredictionDelegate for CodestralEditPredictionDelegate {
buffer: Entity<Buffer>,
cursor_position: language::Anchor,
debounce: bool,
_trigger: EditPredictionRequestTrigger,
cx: &mut Context<Self>,
) {
log::debug!("Codestral: Refresh called (debounce: {})", debounce);
Expand Down
19 changes: 16 additions & 3 deletions crates/copilot/src/copilot_edit_prediction_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
use anyhow::Result;
use edit_prediction_types::{
EditPrediction, EditPredictionDelegate, EditPredictionDiscardReason, EditPredictionIconSet,
interpolate_edits,
EditPredictionRequestTrigger, interpolate_edits,
};
use gpui::{App, Context, Entity, Task, TaskExt};
use icons::IconName;
Expand Down Expand Up @@ -78,6 +78,7 @@ impl EditPredictionDelegate for CopilotEditPredictionDelegate {
buffer: Entity<Buffer>,
cursor_position: language::Anchor,
debounce: bool,
_trigger: EditPredictionRequestTrigger,
cx: &mut Context<Self>,
) {
let copilot = self.copilot.clone();
Expand Down Expand Up @@ -1041,7 +1042,13 @@ mod tests {
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select_ranges([Point::new(0, 0)..Point::new(0, 0)])
});
editor.refresh_edit_prediction(true, false, window, cx);
editor.refresh_edit_prediction(
true,
false,
EditPredictionRequestTrigger::BufferEdit,
window,
cx,
);
});

executor.advance_clock(COPILOT_DEBOUNCE_TIMEOUT);
Expand All @@ -1051,7 +1058,13 @@ mod tests {
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(5, 0)..Point::new(5, 0)])
});
editor.refresh_edit_prediction(true, false, window, cx);
editor.refresh_edit_prediction(
true,
false,
EditPredictionRequestTrigger::BufferEdit,
window,
cx,
);
});

executor.advance_clock(COPILOT_DEBOUNCE_TIMEOUT);
Expand Down
56 changes: 45 additions & 11 deletions crates/edit_prediction/src/edit_prediction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use copilot::{Copilot, Reinstall, SignIn, SignOut};
use credentials_provider::CredentialsProvider;
use db::kvp::{Dismissable, KeyValueStore};
use edit_prediction_context::{RelatedExcerptStore, RelatedExcerptStoreEvent, RelatedFile};
use edit_prediction_types::EditPredictionRequestTrigger;
use feature_flags::{FeatureFlag, FeatureFlagAppExt as _, PresenceFlag, register_feature_flag};
use futures::{
AsyncReadExt as _, FutureExt as _, StreamExt as _,
Expand Down Expand Up @@ -842,6 +843,28 @@ pub(crate) fn buffer_path_with_id_fallback(
}
}

fn predict_edits_request_trigger_from_editor_trigger(
trigger: EditPredictionRequestTrigger,
) -> PredictEditsRequestTrigger {
match trigger {
EditPredictionRequestTrigger::DiagnosticNavigation => {
PredictEditsRequestTrigger::DiagnosticNavigation
}
EditPredictionRequestTrigger::Explicit => PredictEditsRequestTrigger::Explicit,
EditPredictionRequestTrigger::BufferEdit => PredictEditsRequestTrigger::BufferEdit,
EditPredictionRequestTrigger::LSPCompletionAccepted => {
PredictEditsRequestTrigger::LSPCompletionAccepted
}
EditPredictionRequestTrigger::PredictionAccepted => {
PredictEditsRequestTrigger::PredictionAccepted
}
EditPredictionRequestTrigger::PredictionPartiallyAccepted => {
PredictEditsRequestTrigger::PredictionPartiallyAccepted
}
EditPredictionRequestTrigger::Other => PredictEditsRequestTrigger::Other,
}
}

impl EditPredictionStore {
pub fn try_global(cx: &App) -> Option<Entity<Self>> {
cx.try_global::<EditPredictionStoreGlobal>()
Expand Down Expand Up @@ -2215,21 +2238,25 @@ impl EditPredictionStore {
project: Entity<Project>,
buffer: Entity<Buffer>,
position: language::Anchor,
trigger: EditPredictionRequestTrigger,
cx: &mut Context<Self>,
) {
let trigger = predict_edits_request_trigger_from_editor_trigger(trigger);

self.queue_prediction_refresh(
project.clone(),
PredictEditsRequestTrigger::Other,
trigger,
buffer.entity_id(),
cx,
move |this, cx| {
let Some(request_task) = this
.update(cx, |this, cx| {
this.request_prediction(
&project,
&buffer,
this.request_prediction_internal(
project.clone(),
buffer.clone(),
position,
PredictEditsRequestTrigger::Other,
trigger,
cx.has_flag::<EditPredictionJumpsFeatureFlag>(),
cx,
)
})
Expand Down Expand Up @@ -2333,11 +2360,12 @@ impl EditPredictionStore {

let Some(prediction_result) = this
.update(cx, |this, cx| {
this.request_prediction(
&project,
&jump_buffer,
this.request_prediction_internal(
project.clone(),
jump_buffer.clone(),
jump_position,
PredictEditsRequestTrigger::Diagnostics,
cx.has_flag::<EditPredictionJumpsFeatureFlag>(),
cx,
)
})?
Expand Down Expand Up @@ -2454,7 +2482,8 @@ impl EditPredictionStore {
request_trigger: PredictEditsRequestTrigger,
) -> &mut Option<(EntityId, Instant)> {
match request_trigger {
PredictEditsRequestTrigger::Diagnostics => {
PredictEditsRequestTrigger::Diagnostics
| PredictEditsRequestTrigger::DiagnosticNavigation => {
&mut project_state.last_jump_prediction_refresh
}
_ => &mut project_state.last_edit_prediction_refresh,
Expand Down Expand Up @@ -2769,7 +2798,8 @@ impl EditPredictionStore {
inputs.snapshot.clone(),
inputs.position,
match trigger {
PredictEditsRequestTrigger::Diagnostics => {
PredictEditsRequestTrigger::Diagnostics
| PredictEditsRequestTrigger::DiagnosticNavigation => {
JumpExampleTrigger::Diagnostic
}
_ => JumpExampleTrigger::Prediction,
Expand Down Expand Up @@ -2802,7 +2832,11 @@ impl EditPredictionStore {
if prediction.is_none()
&& allow_jump
&& has_events
&& !matches!(trigger, PredictEditsRequestTrigger::Diagnostics)
&& !matches!(
trigger,
PredictEditsRequestTrigger::Diagnostics
| PredictEditsRequestTrigger::DiagnosticNavigation
)
{
this.update(cx, |this, cx| {
this.refresh_prediction_from_diagnostics(
Expand Down
Loading
Loading