completions: Add subtle/eager behavior to Supermaven and Copilot (#35548)

This pull request introduces changes to improve the behavior and
consistency of multiple completion providers
(`CopilotCompletionProvider`, `SupermavenCompletionProvider`) and their
integration with UI elements like menus and inline completion buttons.
It now allows to see the prediction with the completion menu open whilst
pressing `opt` and also enables the subtle/eager setting that was
introduced with zeta.

Edit: I managed to get the preview working with correct icons!
<img width="909" height="232" alt="image"
src="https://github.com/user-attachments/assets/65800e67-4bc4-40f8-be78-806fcfe74ad9"
/>
<img width="1460" height="318" alt="CleanShot 2025-08-04 at 01 36 31@2x"
src="https://github.com/user-attachments/assets/15651405-720f-465f-a13c-c7470817810a"
/>

Correct icons are also displayed:
<img width="244" height="96" alt="image"
src="https://github.com/user-attachments/assets/0b8a687f-73e3-452d-aefb-784c52831b73"
/>


Edit2: I added some comments, would be very happy to receive feedback
(still learning rust)

Release Notes:

- Added Subtle and Eager edit prediction modes to Copilot and Supermaven
This commit is contained in:
Raphael Lüthy 2025-08-07 17:27:29 +02:00 committed by GitHub
parent dd840e4b27
commit 2234220618
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 372 additions and 63 deletions

View file

@ -228,6 +228,49 @@ async fn test_edit_prediction_invalidation_range(cx: &mut gpui::TestAppContext)
});
}
#[gpui::test]
async fn test_edit_prediction_jump_disabled_for_non_zed_providers(cx: &mut gpui::TestAppContext) {
init_test(cx, |_| {});
let mut cx = EditorTestContext::new(cx).await;
let provider = cx.new(|_| FakeNonZedEditPredictionProvider::default());
assign_editor_completion_provider_non_zed(provider.clone(), &mut cx);
// Cursor is 2+ lines above the proposed edit
cx.set_state(indoc! {"
line 0
line ˇ1
line 2
line 3
line
"});
propose_edits_non_zed(
&provider,
vec![(Point::new(4, 3)..Point::new(4, 3), " 4")],
&mut cx,
);
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
// For non-Zed providers, there should be no move completion (jump functionality disabled)
cx.editor(|editor, _, _| {
if let Some(completion_state) = &editor.active_edit_prediction {
// Should be an Edit prediction, not a Move prediction
match &completion_state.completion {
EditPrediction::Edit { .. } => {
// This is expected for non-Zed providers
}
EditPrediction::Move { .. } => {
panic!(
"Non-Zed providers should not show Move predictions (jump functionality)"
);
}
}
}
});
}
fn assert_editor_active_edit_completion(
cx: &mut EditorTestContext,
assert: impl FnOnce(MultiBufferSnapshot, &Vec<(Range<Anchor>, String)>),
@ -301,6 +344,37 @@ fn assign_editor_completion_provider(
})
}
fn propose_edits_non_zed<T: ToOffset>(
provider: &Entity<FakeNonZedEditPredictionProvider>,
edits: Vec<(Range<T>, &str)>,
cx: &mut EditorTestContext,
) {
let snapshot = cx.buffer_snapshot();
let edits = edits.into_iter().map(|(range, text)| {
let range = snapshot.anchor_after(range.start)..snapshot.anchor_before(range.end);
(range, text.into())
});
cx.update(|_, cx| {
provider.update(cx, |provider, _| {
provider.set_edit_prediction(Some(edit_prediction::EditPrediction {
id: None,
edits: edits.collect(),
edit_preview: None,
}))
})
});
}
fn assign_editor_completion_provider_non_zed(
provider: Entity<FakeNonZedEditPredictionProvider>,
cx: &mut EditorTestContext,
) {
cx.update_editor(|editor, window, cx| {
editor.set_edit_prediction_provider(Some(provider), window, cx);
})
}
#[derive(Default, Clone)]
pub struct FakeEditPredictionProvider {
pub completion: Option<edit_prediction::EditPrediction>,
@ -325,6 +399,84 @@ impl EditPredictionProvider for FakeEditPredictionProvider {
false
}
fn supports_jump_to_edit() -> bool {
true
}
fn is_enabled(
&self,
_buffer: &gpui::Entity<language::Buffer>,
_cursor_position: language::Anchor,
_cx: &gpui::App,
) -> bool {
true
}
fn is_refreshing(&self) -> bool {
false
}
fn refresh(
&mut self,
_project: Option<Entity<Project>>,
_buffer: gpui::Entity<language::Buffer>,
_cursor_position: language::Anchor,
_debounce: bool,
_cx: &mut gpui::Context<Self>,
) {
}
fn cycle(
&mut self,
_buffer: gpui::Entity<language::Buffer>,
_cursor_position: language::Anchor,
_direction: edit_prediction::Direction,
_cx: &mut gpui::Context<Self>,
) {
}
fn accept(&mut self, _cx: &mut gpui::Context<Self>) {}
fn discard(&mut self, _cx: &mut gpui::Context<Self>) {}
fn suggest<'a>(
&mut self,
_buffer: &gpui::Entity<language::Buffer>,
_cursor_position: language::Anchor,
_cx: &mut gpui::Context<Self>,
) -> Option<edit_prediction::EditPrediction> {
self.completion.clone()
}
}
#[derive(Default, Clone)]
pub struct FakeNonZedEditPredictionProvider {
pub completion: Option<edit_prediction::EditPrediction>,
}
impl FakeNonZedEditPredictionProvider {
pub fn set_edit_prediction(&mut self, completion: Option<edit_prediction::EditPrediction>) {
self.completion = completion;
}
}
impl EditPredictionProvider for FakeNonZedEditPredictionProvider {
fn name() -> &'static str {
"fake-non-zed-provider"
}
fn display_name() -> &'static str {
"Fake Non-Zed Provider"
}
fn show_completions_in_menu() -> bool {
false
}
fn supports_jump_to_edit() -> bool {
false
}
fn is_enabled(
&self,
_buffer: &gpui::Entity<language::Buffer>,

View file

@ -7760,8 +7760,14 @@ impl Editor {
} else {
None
};
let is_move =
move_invalidation_row_range.is_some() || self.edit_predictions_hidden_for_vim_mode;
let supports_jump = self
.edit_prediction_provider
.as_ref()
.map(|provider| provider.provider.supports_jump_to_edit())
.unwrap_or(true);
let is_move = supports_jump
&& (move_invalidation_row_range.is_some() || self.edit_predictions_hidden_for_vim_mode);
let completion = if is_move {
invalidation_row_range =
move_invalidation_row_range.unwrap_or(edit_start_row..edit_end_row);
@ -8799,8 +8805,12 @@ impl Editor {
return None;
}
let highlighted_edits =
crate::edit_prediction_edit_text(&snapshot, edits, edit_preview.as_ref()?, false, cx);
let highlighted_edits = if let Some(edit_preview) = edit_preview.as_ref() {
crate::edit_prediction_edit_text(&snapshot, edits, edit_preview, false, cx)
} else {
// Fallback for providers without edit_preview
crate::edit_prediction_fallback_text(edits, cx)
};
let styled_text = highlighted_edits.to_styled_text(&style.text);
let line_count = highlighted_edits.text.lines().count();
@ -9068,6 +9078,18 @@ impl Editor {
let editor_bg_color = cx.theme().colors().editor_background;
editor_bg_color.blend(accent_color.opacity(0.6))
}
fn get_prediction_provider_icon_name(
provider: &Option<RegisteredEditPredictionProvider>,
) -> IconName {
match provider {
Some(provider) => match provider.provider.name() {
"copilot" => IconName::Copilot,
"supermaven" => IconName::Supermaven,
_ => IconName::ZedPredict,
},
None => IconName::ZedPredict,
}
}
fn render_edit_prediction_cursor_popover(
&self,
@ -9080,6 +9102,7 @@ impl Editor {
cx: &mut Context<Editor>,
) -> Option<AnyElement> {
let provider = self.edit_prediction_provider.as_ref()?;
let provider_icon = Self::get_prediction_provider_icon_name(&self.edit_prediction_provider);
if provider.provider.needs_terms_acceptance(cx) {
return Some(
@ -9106,7 +9129,7 @@ impl Editor {
h_flex()
.flex_1()
.gap_2()
.child(Icon::new(IconName::ZedPredict))
.child(Icon::new(provider_icon))
.child(Label::new("Accept Terms of Service"))
.child(div().w_full())
.child(
@ -9122,12 +9145,8 @@ impl Editor {
let is_refreshing = provider.provider.is_refreshing(cx);
fn pending_completion_container() -> Div {
h_flex()
.h_full()
.flex_1()
.gap_2()
.child(Icon::new(IconName::ZedPredict))
fn pending_completion_container(icon: IconName) -> Div {
h_flex().h_full().flex_1().gap_2().child(Icon::new(icon))
}
let completion = match &self.active_edit_prediction {
@ -9157,7 +9176,7 @@ impl Editor {
Icon::new(IconName::ZedPredictUp)
}
}
EditPrediction::Edit { .. } => Icon::new(IconName::ZedPredict),
EditPrediction::Edit { .. } => Icon::new(provider_icon),
}))
.child(
h_flex()
@ -9224,15 +9243,15 @@ impl Editor {
cx,
)?,
None => {
pending_completion_container().child(Label::new("...").size(LabelSize::Small))
}
None => pending_completion_container(provider_icon)
.child(Label::new("...").size(LabelSize::Small)),
},
None => pending_completion_container().child(Label::new("No Prediction")),
None => pending_completion_container(provider_icon)
.child(Label::new("...").size(LabelSize::Small)),
};
let completion = if is_refreshing {
let completion = if is_refreshing || self.active_edit_prediction.is_none() {
completion
.with_animation(
"loading-completion",
@ -9332,23 +9351,35 @@ impl Editor {
.child(Icon::new(arrow).color(Color::Muted).size(IconSize::Small))
}
let supports_jump = self
.edit_prediction_provider
.as_ref()
.map(|provider| provider.provider.supports_jump_to_edit())
.unwrap_or(true);
match &completion.completion {
EditPrediction::Move {
target, snapshot, ..
} => Some(
h_flex()
.px_2()
.gap_2()
.flex_1()
.child(
if target.text_anchor.to_point(&snapshot).row > cursor_point.row {
Icon::new(IconName::ZedPredictDown)
} else {
Icon::new(IconName::ZedPredictUp)
},
)
.child(Label::new("Jump to Edit")),
),
} => {
if !supports_jump {
return None;
}
Some(
h_flex()
.px_2()
.gap_2()
.flex_1()
.child(
if target.text_anchor.to_point(&snapshot).row > cursor_point.row {
Icon::new(IconName::ZedPredictDown)
} else {
Icon::new(IconName::ZedPredictUp)
},
)
.child(Label::new("Jump to Edit")),
)
}
EditPrediction::Edit {
edits,
@ -9358,14 +9389,13 @@ impl Editor {
} => {
let first_edit_row = edits.first()?.0.start.text_anchor.to_point(&snapshot).row;
let (highlighted_edits, has_more_lines) = crate::edit_prediction_edit_text(
&snapshot,
&edits,
edit_preview.as_ref()?,
true,
cx,
)
.first_line_preview();
let (highlighted_edits, has_more_lines) =
if let Some(edit_preview) = edit_preview.as_ref() {
crate::edit_prediction_edit_text(&snapshot, &edits, edit_preview, true, cx)
.first_line_preview()
} else {
crate::edit_prediction_fallback_text(&edits, cx).first_line_preview()
};
let styled_text = gpui::StyledText::new(highlighted_edits.text)
.with_default_highlights(&style.text, highlighted_edits.highlights);
@ -9376,11 +9406,13 @@ impl Editor {
.child(styled_text)
.when(has_more_lines, |parent| parent.child(""));
let left = if first_edit_row != cursor_point.row {
let left = if supports_jump && first_edit_row != cursor_point.row {
render_relative_row_jump("", cursor_point.row, first_edit_row)
.into_any_element()
} else {
Icon::new(IconName::ZedPredict).into_any_element()
let icon_name =
Editor::get_prediction_provider_icon_name(&self.edit_prediction_provider);
Icon::new(icon_name).into_any_element()
};
Some(
@ -23270,6 +23302,33 @@ fn edit_prediction_edit_text(
edit_preview.highlight_edits(current_snapshot, &edits, include_deletions, cx)
}
fn edit_prediction_fallback_text(edits: &[(Range<Anchor>, String)], cx: &App) -> HighlightedText {
// Fallback for providers that don't provide edit_preview (like Copilot/Supermaven)
// Just show the raw edit text with basic styling
let mut text = String::new();
let mut highlights = Vec::new();
let insertion_highlight_style = HighlightStyle {
color: Some(cx.theme().colors().text),
..Default::default()
};
for (_, edit_text) in edits {
let start_offset = text.len();
text.push_str(edit_text);
let end_offset = text.len();
if start_offset < end_offset {
highlights.push((start_offset..end_offset, insertion_highlight_style));
}
}
HighlightedText {
text: text.into(),
highlights,
}
}
pub fn diagnostic_style(severity: lsp::DiagnosticSeverity, colors: &StatusColors) -> Hsla {
match severity {
lsp::DiagnosticSeverity::ERROR => colors.error,