zeta: Various product fixes before Preview release (#23125)
Various fixes for Zeta and one fix that's visible to non-Zeta-using users of inline completions. Release Notes: - Changed inline completions (Copilot, Supermaven, ...) to not show up in empty buffers. --------- Co-authored-by: Antonio <antonio@zed.dev> Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
parent
1b3b825c7f
commit
a67709629b
6 changed files with 247 additions and 121 deletions
|
@ -1,13 +1,11 @@
|
|||
use crate::{InlineCompletion, InlineCompletionRating, Zeta};
|
||||
use crate::{CompletionDiffElement, InlineCompletion, InlineCompletionRating, Zeta};
|
||||
use editor::Editor;
|
||||
use gpui::{
|
||||
actions, prelude::*, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView,
|
||||
HighlightStyle, Model, StyledText, TextStyle, View, ViewContext,
|
||||
actions, prelude::*, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView, Model,
|
||||
View, ViewContext,
|
||||
};
|
||||
use language::{language_settings, OffsetRangeExt};
|
||||
use settings::Settings;
|
||||
use language::language_settings;
|
||||
use std::time::Duration;
|
||||
use theme::ThemeSettings;
|
||||
use ui::{prelude::*, KeyBinding, List, ListItem, ListItemSpacing, Tooltip};
|
||||
use workspace::{ModalView, Workspace};
|
||||
|
||||
|
@ -73,7 +71,7 @@ impl RateCompletionModal {
|
|||
self.selected_index += 1;
|
||||
self.selected_index = usize::min(
|
||||
self.selected_index,
|
||||
self.zeta.read(cx).recent_completions().count(),
|
||||
self.zeta.read(cx).shown_completions().count(),
|
||||
);
|
||||
cx.notify();
|
||||
}
|
||||
|
@ -87,7 +85,7 @@ impl RateCompletionModal {
|
|||
let next_index = self
|
||||
.zeta
|
||||
.read(cx)
|
||||
.recent_completions()
|
||||
.shown_completions()
|
||||
.skip(self.selected_index)
|
||||
.enumerate()
|
||||
.skip(1) // Skip straight to the next item
|
||||
|
@ -102,12 +100,12 @@ impl RateCompletionModal {
|
|||
|
||||
fn select_prev_edit(&mut self, _: &PreviousEdit, cx: &mut ViewContext<Self>) {
|
||||
let zeta = self.zeta.read(cx);
|
||||
let completions_len = zeta.recent_completions_len();
|
||||
let completions_len = zeta.shown_completions_len();
|
||||
|
||||
let prev_index = self
|
||||
.zeta
|
||||
.read(cx)
|
||||
.recent_completions()
|
||||
.shown_completions()
|
||||
.rev()
|
||||
.skip((completions_len - 1) - self.selected_index)
|
||||
.enumerate()
|
||||
|
@ -128,11 +126,11 @@ impl RateCompletionModal {
|
|||
}
|
||||
|
||||
fn select_last(&mut self, _: &menu::SelectLast, cx: &mut ViewContext<Self>) {
|
||||
self.selected_index = self.zeta.read(cx).recent_completions_len() - 1;
|
||||
self.selected_index = self.zeta.read(cx).shown_completions_len() - 1;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn thumbs_up_active(&mut self, _: &ThumbsUpActiveCompletion, cx: &mut ViewContext<Self>) {
|
||||
pub fn thumbs_up_active(&mut self, _: &ThumbsUpActiveCompletion, cx: &mut ViewContext<Self>) {
|
||||
self.zeta.update(cx, |zeta, cx| {
|
||||
if let Some(active) = &self.active_completion {
|
||||
zeta.rate_completion(
|
||||
|
@ -155,7 +153,11 @@ impl RateCompletionModal {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
fn thumbs_down_active(&mut self, _: &ThumbsDownActiveCompletion, cx: &mut ViewContext<Self>) {
|
||||
pub fn thumbs_down_active(
|
||||
&mut self,
|
||||
_: &ThumbsDownActiveCompletion,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
if let Some(active) = &self.active_completion {
|
||||
if active.feedback_editor.read(cx).text(cx).is_empty() {
|
||||
return;
|
||||
|
@ -191,7 +193,7 @@ impl RateCompletionModal {
|
|||
let completion = self
|
||||
.zeta
|
||||
.read(cx)
|
||||
.recent_completions()
|
||||
.shown_completions()
|
||||
.skip(self.selected_index)
|
||||
.take(1)
|
||||
.next()
|
||||
|
@ -204,7 +206,7 @@ impl RateCompletionModal {
|
|||
let completion = self
|
||||
.zeta
|
||||
.read(cx)
|
||||
.recent_completions()
|
||||
.shown_completions()
|
||||
.skip(self.selected_index)
|
||||
.take(1)
|
||||
.next()
|
||||
|
@ -224,7 +226,7 @@ impl RateCompletionModal {
|
|||
self.selected_index = self
|
||||
.zeta
|
||||
.read(cx)
|
||||
.recent_completions()
|
||||
.shown_completions()
|
||||
.enumerate()
|
||||
.find(|(_, completion_b)| completion.id == completion_b.id)
|
||||
.map(|(ix, _)| ix)
|
||||
|
@ -269,64 +271,10 @@ impl RateCompletionModal {
|
|||
let completion_id = active_completion.completion.id;
|
||||
let focus_handle = &self.focus_handle(cx);
|
||||
|
||||
let mut diff = active_completion
|
||||
.completion
|
||||
.snapshot
|
||||
.text_for_range(active_completion.completion.excerpt_range.clone())
|
||||
.collect::<String>();
|
||||
|
||||
let mut delta = 0;
|
||||
let mut diff_highlights = Vec::new();
|
||||
for (old_range, new_text) in active_completion.completion.edits.iter() {
|
||||
let old_range = old_range.to_offset(&active_completion.completion.snapshot);
|
||||
let old_start_in_text =
|
||||
old_range.start - active_completion.completion.excerpt_range.start + delta;
|
||||
let old_end_in_text =
|
||||
old_range.end - active_completion.completion.excerpt_range.start + delta;
|
||||
if old_start_in_text < old_end_in_text {
|
||||
diff_highlights.push((
|
||||
old_start_in_text..old_end_in_text,
|
||||
HighlightStyle {
|
||||
background_color: Some(cx.theme().status().deleted_background),
|
||||
strikethrough: Some(gpui::StrikethroughStyle {
|
||||
thickness: px(1.),
|
||||
color: Some(cx.theme().colors().text_muted),
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
if !new_text.is_empty() {
|
||||
diff.insert_str(old_end_in_text, new_text);
|
||||
diff_highlights.push((
|
||||
old_end_in_text..old_end_in_text + new_text.len(),
|
||||
HighlightStyle {
|
||||
background_color: Some(cx.theme().status().created_background),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
delta += new_text.len();
|
||||
}
|
||||
}
|
||||
|
||||
let settings = ThemeSettings::get_global(cx).clone();
|
||||
let text_style = TextStyle {
|
||||
color: cx.theme().colors().editor_foreground,
|
||||
font_size: settings.buffer_font_size(cx).into(),
|
||||
font_family: settings.buffer_font.family,
|
||||
font_features: settings.buffer_font.features,
|
||||
font_fallbacks: settings.buffer_font.fallbacks,
|
||||
line_height: relative(settings.buffer_line_height.value()),
|
||||
font_weight: settings.buffer_font.weight,
|
||||
font_style: settings.buffer_font.style,
|
||||
..Default::default()
|
||||
};
|
||||
let border_color = cx.theme().colors().border;
|
||||
let bg_color = cx.theme().colors().editor_background;
|
||||
|
||||
let rated = self.zeta.read(cx).is_completion_rated(completion_id);
|
||||
let was_shown = self.zeta.read(cx).was_completion_shown(completion_id);
|
||||
let feedback_empty = active_completion
|
||||
.feedback_editor
|
||||
.read(cx)
|
||||
|
@ -347,7 +295,8 @@ impl RateCompletionModal {
|
|||
.size_full()
|
||||
.bg(bg_color)
|
||||
.overflow_scroll()
|
||||
.child(StyledText::new(diff).with_highlights(&text_style, diff_highlights)),
|
||||
.whitespace_nowrap()
|
||||
.child(CompletionDiffElement::new(&active_completion.completion, cx)),
|
||||
)
|
||||
.when_some((!rated).then(|| ()), |this, _| {
|
||||
this.child(
|
||||
|
@ -413,16 +362,6 @@ impl RateCompletionModal {
|
|||
)
|
||||
.child(Label::new("No edits produced.").color(Color::Muted)),
|
||||
)
|
||||
} else if !was_shown {
|
||||
Some(
|
||||
label_container()
|
||||
.child(
|
||||
Icon::new(IconName::Warning)
|
||||
.size(IconSize::Small)
|
||||
.color(Color::Warning),
|
||||
)
|
||||
.child(Label::new("Completion wasn't shown because another valid one was already on screen.")),
|
||||
)
|
||||
} else {
|
||||
Some(label_container())
|
||||
})
|
||||
|
@ -541,7 +480,7 @@ impl Render for RateCompletionModal {
|
|||
)
|
||||
.into_any_element(),
|
||||
)
|
||||
.children(self.zeta.read(cx).recent_completions().cloned().enumerate().map(
|
||||
.children(self.zeta.read(cx).shown_completions().cloned().enumerate().map(
|
||||
|(index, completion)| {
|
||||
let selected =
|
||||
self.active_completion.as_ref().map_or(false, |selected| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue