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:
parent
dd840e4b27
commit
2234220618
7 changed files with 372 additions and 63 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue