Show "tab Accept" only for zeta (#23463)
#23460 brought up we are showing the new "tab Accept" marker for single line suggestions for non-zeta providers. We think this might be valid for any provider, but we only want to enable it for zeta initially so it doesn't affect an existing user base. Release Notes: - N/A
This commit is contained in:
parent
1e88e2924c
commit
95cde129af
5 changed files with 85 additions and 53 deletions
|
@ -485,10 +485,16 @@ enum InlineCompletionText {
|
|||
},
|
||||
}
|
||||
|
||||
pub(crate) enum EditDisplayMode {
|
||||
TabAccept,
|
||||
DiffPopover,
|
||||
Inline,
|
||||
}
|
||||
|
||||
enum InlineCompletion {
|
||||
Edit {
|
||||
edits: Vec<(Range<Anchor>, String)>,
|
||||
single_line: bool,
|
||||
display_mode: EditDisplayMode,
|
||||
},
|
||||
Move(Anchor),
|
||||
}
|
||||
|
@ -4691,7 +4697,7 @@ impl Editor {
|
|||
}
|
||||
InlineCompletion::Edit {
|
||||
edits,
|
||||
single_line: _,
|
||||
display_mode: _,
|
||||
} => {
|
||||
if let Some(provider) = self.inline_completion_provider() {
|
||||
provider.accept(cx);
|
||||
|
@ -4741,7 +4747,7 @@ impl Editor {
|
|||
}
|
||||
InlineCompletion::Edit {
|
||||
edits,
|
||||
single_line: _,
|
||||
display_mode: _,
|
||||
} => {
|
||||
// Find an insertion that starts at the cursor position.
|
||||
let snapshot = self.buffer.read(cx).snapshot(cx);
|
||||
|
@ -4941,10 +4947,23 @@ impl Editor {
|
|||
|
||||
invalidation_row_range = edit_start_row..edit_end_row;
|
||||
|
||||
let single_line = first_edit_start_point.row == last_edit_end_point.row
|
||||
&& !edits.iter().any(|(_, edit)| edit.contains('\n'));
|
||||
let display_mode = if all_edits_insertions_or_deletions(&edits, &multibuffer) {
|
||||
if provider.show_tab_accept_marker()
|
||||
&& first_edit_start_point.row == last_edit_end_point.row
|
||||
&& !edits.iter().any(|(_, edit)| edit.contains('\n'))
|
||||
{
|
||||
EditDisplayMode::TabAccept
|
||||
} else {
|
||||
EditDisplayMode::Inline
|
||||
}
|
||||
} else {
|
||||
EditDisplayMode::DiffPopover
|
||||
};
|
||||
|
||||
completion = InlineCompletion::Edit { edits, single_line };
|
||||
completion = InlineCompletion::Edit {
|
||||
edits,
|
||||
display_mode,
|
||||
};
|
||||
};
|
||||
|
||||
let invalidation_range = multibuffer
|
||||
|
@ -4987,7 +5006,7 @@ impl Editor {
|
|||
let text = match &self.active_inline_completion.as_ref()?.completion {
|
||||
InlineCompletion::Edit {
|
||||
edits,
|
||||
single_line: _,
|
||||
display_mode: _,
|
||||
} => inline_completion_edit_text(&editor_snapshot, edits, true, cx),
|
||||
InlineCompletion::Move(target) => {
|
||||
let target_point =
|
||||
|
@ -15275,3 +15294,31 @@ pub struct KillRing(ClipboardItem);
|
|||
impl Global for KillRing {}
|
||||
|
||||
const UPDATE_DEBOUNCE: Duration = Duration::from_millis(50);
|
||||
|
||||
fn all_edits_insertions_or_deletions(
|
||||
edits: &Vec<(Range<Anchor>, String)>,
|
||||
snapshot: &MultiBufferSnapshot,
|
||||
) -> bool {
|
||||
let mut all_insertions = true;
|
||||
let mut all_deletions = true;
|
||||
|
||||
for (range, new_text) in edits.iter() {
|
||||
let range_is_empty = range.to_offset(&snapshot).is_empty();
|
||||
let text_is_empty = new_text.is_empty();
|
||||
|
||||
if range_is_empty != text_is_empty {
|
||||
if range_is_empty {
|
||||
all_deletions = false;
|
||||
} else {
|
||||
all_insertions = false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if !all_insertions && !all_deletions {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
all_insertions || all_deletions
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue