Compare commits
2 Commits
mac-focus-
...
fix-user-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd7552f826 | ||
|
|
e737c6d790 |
@@ -22,7 +22,7 @@ async fn test_edit_prediction_insert(cx: &mut gpui::TestAppContext) {
|
||||
cx.set_state("let absolute_zero_celsius = ˇ;");
|
||||
|
||||
propose_edits(&provider, vec![(28..28, "-273.15")], &mut cx);
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
|
||||
assert_editor_active_edit_completion(&mut cx, |_, edits| {
|
||||
assert_eq!(edits.len(), 1);
|
||||
@@ -44,7 +44,7 @@ async fn test_edit_prediction_modification(cx: &mut gpui::TestAppContext) {
|
||||
cx.set_state("let pi = ˇ\"foo\";");
|
||||
|
||||
propose_edits(&provider, vec![(9..14, "3.14159")], &mut cx);
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
|
||||
assert_editor_active_edit_completion(&mut cx, |_, edits| {
|
||||
assert_eq!(edits.len(), 1);
|
||||
@@ -79,7 +79,7 @@ async fn test_edit_prediction_jump_button(cx: &mut gpui::TestAppContext) {
|
||||
&mut cx,
|
||||
);
|
||||
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
assert_editor_active_move_completion(&mut cx, |snapshot, move_target| {
|
||||
assert_eq!(move_target.to_point(&snapshot), Point::new(4, 3));
|
||||
});
|
||||
@@ -109,7 +109,7 @@ async fn test_edit_prediction_jump_button(cx: &mut gpui::TestAppContext) {
|
||||
&mut cx,
|
||||
);
|
||||
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
assert_editor_active_move_completion(&mut cx, |snapshot, move_target| {
|
||||
assert_eq!(move_target.to_point(&snapshot), Point::new(1, 3));
|
||||
});
|
||||
@@ -150,7 +150,7 @@ async fn test_edit_prediction_invalidation_range(cx: &mut gpui::TestAppContext)
|
||||
&mut cx,
|
||||
);
|
||||
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
assert_editor_active_move_completion(&mut cx, |snapshot, move_target| {
|
||||
assert_eq!(move_target.to_point(&snapshot), edit_location);
|
||||
});
|
||||
@@ -198,7 +198,7 @@ async fn test_edit_prediction_invalidation_range(cx: &mut gpui::TestAppContext)
|
||||
&mut cx,
|
||||
);
|
||||
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
assert_editor_active_move_completion(&mut cx, |snapshot, move_target| {
|
||||
assert_eq!(move_target.to_point(&snapshot), edit_location);
|
||||
});
|
||||
@@ -253,7 +253,7 @@ async fn test_edit_prediction_jump_disabled_for_non_zed_providers(cx: &mut gpui:
|
||||
&mut cx,
|
||||
);
|
||||
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
|
||||
// For non-Zed providers, there should be no move completion (jump functionality disabled)
|
||||
cx.editor(|editor, _, _| {
|
||||
@@ -288,10 +288,21 @@ async fn test_edit_predictions_disabled_in_scope(cx: &mut gpui::TestAppContext)
|
||||
let language = languages::language("javascript", tree_sitter_typescript::LANGUAGE_TSX.into());
|
||||
cx.update_buffer(|buffer, cx| buffer.set_language(Some(language), cx));
|
||||
|
||||
// Test enabled outside of string
|
||||
cx.set_state("const x = \"hello world\"; ˇ");
|
||||
propose_edits(&provider, vec![(24..24, "// comment")], &mut cx);
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
cx.editor(|editor, _, _| {
|
||||
assert!(
|
||||
editor.active_edit_prediction.is_some(),
|
||||
"Edit predictions should work outside of disabled scopes"
|
||||
);
|
||||
});
|
||||
|
||||
// Test disabled inside of string
|
||||
cx.set_state("const x = \"hello ˇworld\";");
|
||||
propose_edits(&provider, vec![(17..17, "beautiful ")], &mut cx);
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
cx.editor(|editor, _, _| {
|
||||
assert!(
|
||||
editor.active_edit_prediction.is_none(),
|
||||
@@ -299,18 +310,79 @@ async fn test_edit_predictions_disabled_in_scope(cx: &mut gpui::TestAppContext)
|
||||
);
|
||||
});
|
||||
|
||||
// Test enabled outside of string
|
||||
cx.set_state("const x = \"hello world\"; ˇ");
|
||||
propose_edits(&provider, vec![(24..24, "// comment")], &mut cx);
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
|
||||
// Test even when disabled in scope, user requested prediction should show
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
editor.show_edit_prediction(&crate::ShowEditPrediction, window, cx)
|
||||
});
|
||||
cx.editor(|editor, _, _| {
|
||||
assert!(
|
||||
editor.active_edit_prediction.is_some(),
|
||||
"Edit predictions should work outside of disabled scopes"
|
||||
"User-requested ShowEditPrediction should display despite disabled scope"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_user_requested_predictions(cx: &mut gpui::TestAppContext) {
|
||||
init_test(cx, |_| {});
|
||||
|
||||
update_test_language_settings(cx, |settings| {
|
||||
settings.defaults.show_edit_predictions = Some(false);
|
||||
});
|
||||
|
||||
let mut cx = EditorTestContext::new(cx).await;
|
||||
let provider = cx.new(|_| FakeEditPredictionProvider::default());
|
||||
assign_editor_completion_provider(provider.clone(), &mut cx);
|
||||
|
||||
cx.set_state("let value = ˇ;");
|
||||
propose_edits(&provider, vec![(12..12, "42")], &mut cx);
|
||||
|
||||
// Test with global setting disabled, non user requested update should not show
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
cx.editor(|editor, _, _| {
|
||||
assert!(editor.active_edit_prediction.is_none());
|
||||
});
|
||||
|
||||
// Test ShowEditPrediction shows prediction even `show_edit_predictions` as `false`
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
editor.show_edit_prediction(&crate::ShowEditPrediction, window, cx)
|
||||
});
|
||||
assert_editor_active_edit_completion(&mut cx, |_, edits| {
|
||||
assert_eq!(edits.len(), 1);
|
||||
assert_eq!(edits[0].1.as_str(), "42");
|
||||
});
|
||||
|
||||
// clear
|
||||
cx.update_editor(|editor, _, cx| editor.take_active_edit_prediction(cx));
|
||||
cx.editor(|editor, _, _| {
|
||||
assert!(editor.active_edit_prediction.is_none());
|
||||
});
|
||||
|
||||
// Test PreviousEditPrediction shows prediction even `show_edit_predictions` as `false`
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
editor.previous_edit_prediction(&crate::PreviousEditPrediction, window, cx)
|
||||
});
|
||||
assert_editor_active_edit_completion(&mut cx, |_, edits| {
|
||||
assert_eq!(edits.len(), 1);
|
||||
assert_eq!(edits[0].1.as_str(), "42");
|
||||
});
|
||||
|
||||
// clear
|
||||
cx.update_editor(|editor, _, cx| editor.take_active_edit_prediction(cx));
|
||||
cx.editor(|editor, _, _| {
|
||||
assert!(editor.active_edit_prediction.is_none());
|
||||
});
|
||||
|
||||
// Test NextEditPrediction shows prediction even `show_edit_predictions` as `false`
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
editor.next_edit_prediction(&crate::NextEditPrediction, window, cx)
|
||||
});
|
||||
assert_editor_active_edit_completion(&mut cx, |_, edits| {
|
||||
assert_eq!(edits.len(), 1);
|
||||
assert_eq!(edits[0].1.as_str(), "42");
|
||||
});
|
||||
}
|
||||
|
||||
fn assert_editor_active_edit_completion(
|
||||
cx: &mut EditorTestContext,
|
||||
assert: impl FnOnce(MultiBufferSnapshot, &Vec<(Range<Anchor>, String)>),
|
||||
|
||||
@@ -2818,7 +2818,7 @@ impl Editor {
|
||||
self.edit_prediction_provider = provider.map(|provider| RegisteredEditPredictionProvider {
|
||||
_subscription: cx.observe_in(&provider, window, |this, _, window, cx| {
|
||||
if this.focus_handle.is_focused(window) {
|
||||
this.update_visible_edit_prediction(window, cx);
|
||||
this.update_visible_edit_prediction(false, window, cx);
|
||||
}
|
||||
}),
|
||||
provider: Arc::new(provider),
|
||||
@@ -2921,7 +2921,7 @@ impl Editor {
|
||||
if hidden != self.edit_predictions_hidden_for_vim_mode {
|
||||
self.edit_predictions_hidden_for_vim_mode = hidden;
|
||||
if hidden {
|
||||
self.update_visible_edit_prediction(window, cx);
|
||||
self.update_visible_edit_prediction(false, window, cx);
|
||||
} else {
|
||||
self.refresh_edit_prediction(true, false, window, cx);
|
||||
}
|
||||
@@ -3157,7 +3157,7 @@ impl Editor {
|
||||
self.refresh_document_highlights(cx);
|
||||
self.refresh_selected_text_highlights(false, window, cx);
|
||||
refresh_matching_bracket_highlights(self, window, cx);
|
||||
self.update_visible_edit_prediction(window, cx);
|
||||
self.update_visible_edit_prediction(false, window, cx);
|
||||
self.edit_prediction_requires_modifier_in_indent_conflict = true;
|
||||
linked_editing_ranges::refresh_linked_ranges(self, window, cx);
|
||||
self.inline_blame_popover.take();
|
||||
@@ -5813,7 +5813,7 @@ impl Editor {
|
||||
|
||||
crate::hover_popover::hide_hover(editor, cx);
|
||||
if editor.show_edit_predictions_in_menu() {
|
||||
editor.update_visible_edit_prediction(window, cx);
|
||||
editor.update_visible_edit_prediction(false, window, cx);
|
||||
} else {
|
||||
editor.discard_edit_prediction(false, cx);
|
||||
}
|
||||
@@ -5828,7 +5828,7 @@ impl Editor {
|
||||
// If it was already hidden and we don't show edit predictions in the menu,
|
||||
// we should also show the edit prediction when available.
|
||||
if was_hidden && editor.show_edit_predictions_in_menu() {
|
||||
editor.update_visible_edit_prediction(window, cx);
|
||||
editor.update_visible_edit_prediction(false, window, cx);
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -7161,7 +7161,7 @@ impl Editor {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.update_visible_edit_prediction(window, cx);
|
||||
self.update_visible_edit_prediction(user_requested, window, cx);
|
||||
provider.refresh(
|
||||
self.project.clone(),
|
||||
buffer,
|
||||
@@ -7319,7 +7319,7 @@ impl Editor {
|
||||
}
|
||||
|
||||
provider.cycle(buffer, cursor_buffer_position, direction, cx);
|
||||
self.update_visible_edit_prediction(window, cx);
|
||||
self.update_visible_edit_prediction(true, window, cx);
|
||||
|
||||
Some(())
|
||||
}
|
||||
@@ -7335,7 +7335,7 @@ impl Editor {
|
||||
return;
|
||||
}
|
||||
|
||||
self.update_visible_edit_prediction(window, cx);
|
||||
self.update_visible_edit_prediction(true, window, cx);
|
||||
}
|
||||
|
||||
pub fn display_cursor_names(
|
||||
@@ -7484,7 +7484,7 @@ impl Editor {
|
||||
}
|
||||
}
|
||||
|
||||
self.update_visible_edit_prediction(window, cx);
|
||||
self.update_visible_edit_prediction(false, window, cx);
|
||||
if self.active_edit_prediction.is_none() {
|
||||
self.refresh_edit_prediction(true, true, window, cx);
|
||||
}
|
||||
@@ -7774,7 +7774,7 @@ impl Editor {
|
||||
since: Instant::now(),
|
||||
};
|
||||
|
||||
self.update_visible_edit_prediction(window, cx);
|
||||
self.update_visible_edit_prediction(false, window, cx);
|
||||
cx.notify();
|
||||
}
|
||||
} else if let EditPredictionPreview::Active {
|
||||
@@ -7797,13 +7797,14 @@ impl Editor {
|
||||
released_too_fast: since.elapsed() < Duration::from_millis(200),
|
||||
};
|
||||
self.clear_row_highlights::<EditPredictionPreview>();
|
||||
self.update_visible_edit_prediction(window, cx);
|
||||
self.update_visible_edit_prediction(false, window, cx);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn update_visible_edit_prediction(
|
||||
&mut self,
|
||||
user_requested: bool,
|
||||
_window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<()> {
|
||||
@@ -7854,10 +7855,16 @@ impl Editor {
|
||||
self.edit_prediction_settings =
|
||||
self.edit_prediction_settings_at_position(&buffer, cursor_buffer_position, cx);
|
||||
|
||||
if let EditPredictionSettings::Disabled = self.edit_prediction_settings {
|
||||
// if user explicitly requested edit prediction, we should show despite disabled setting
|
||||
if !user_requested
|
||||
&& matches!(
|
||||
self.edit_prediction_settings,
|
||||
EditPredictionSettings::Disabled
|
||||
)
|
||||
{
|
||||
self.discard_edit_prediction(false, cx);
|
||||
return None;
|
||||
};
|
||||
}
|
||||
|
||||
self.edit_prediction_indent_conflict = multibuffer.is_line_whitespace_upto(cursor);
|
||||
|
||||
@@ -9575,7 +9582,7 @@ impl Editor {
|
||||
self.completion_tasks.clear();
|
||||
let context_menu = self.context_menu.borrow_mut().take();
|
||||
self.stale_edit_prediction_in_menu.take();
|
||||
self.update_visible_edit_prediction(window, cx);
|
||||
self.update_visible_edit_prediction(false, window, cx);
|
||||
if let Some(CodeContextMenu::Completions(_)) = &context_menu
|
||||
&& let Some(completion_provider) = &self.completion_provider
|
||||
{
|
||||
@@ -20569,7 +20576,7 @@ impl Editor {
|
||||
self.refresh_single_line_folds(window, cx);
|
||||
refresh_matching_bracket_highlights(self, window, cx);
|
||||
if self.has_active_edit_prediction() {
|
||||
self.update_visible_edit_prediction(window, cx);
|
||||
self.update_visible_edit_prediction(false, window, cx);
|
||||
}
|
||||
if let Some(project) = self.project.as_ref()
|
||||
&& let Some(edited_buffer) = edited_buffer
|
||||
|
||||
@@ -8271,7 +8271,7 @@ async fn test_undo_edit_prediction_scrolls_to_edit_pos(cx: &mut TestAppContext)
|
||||
})
|
||||
});
|
||||
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(window, cx));
|
||||
cx.update_editor(|editor, window, cx| editor.update_visible_edit_prediction(false, window, cx));
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
editor.accept_edit_prediction(&crate::AcceptEditPrediction, window, cx)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user