Splice remove suggesion hints when those are cleared in the editor. (#9088)

Closes https://github.com/zed-industries/zed/issues/6793

Release Notes:

- Fixed copilot suggestions not disappearing after disabling the tool
([6793](https://github.com/zed-industries/zed/issues/6793))
This commit is contained in:
Kirill Bulatov 2024-03-09 02:00:01 +02:00 committed by GitHub
parent 347178039c
commit 146971fb02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 12 deletions

View file

@ -149,7 +149,7 @@ impl CopilotButton {
pub fn build_copilot_menu(&mut self, cx: &mut ViewContext<Self>) -> View<ContextMenu> {
let fs = self.fs.clone();
return ContextMenu::build(cx, move |mut menu, cx| {
ContextMenu::build(cx, move |mut menu, cx| {
if let Some(language) = self.language.clone() {
let fs = fs.clone();
let language_enabled =
@ -216,7 +216,7 @@ impl CopilotButton {
.boxed_clone(),
)
.action("Sign Out", SignOut.boxed_clone())
});
})
}
pub fn update_enabled(&mut self, editor: View<Editor>, cx: &mut ViewContext<Self>) {

View file

@ -1215,6 +1215,7 @@ impl CodeActionsMenu {
}
}
#[derive(Debug)]
pub(crate) struct CopilotState {
excerpt_id: Option<ExcerptId>,
pending_refresh: Task<Option<()>>,
@ -3114,7 +3115,7 @@ impl Editor {
(InvalidationStrategy::RefreshRequested, None)
} else {
self.inlay_hint_cache.clear();
self.splice_inlay_hints(
self.splice_inlays(
self.visible_inlay_hints(cx)
.iter()
.map(|inlay| inlay.id)
@ -3136,7 +3137,7 @@ impl Editor {
to_remove,
to_insert,
})) => {
self.splice_inlay_hints(to_remove, to_insert, cx);
self.splice_inlays(to_remove, to_insert, cx);
return;
}
ControlFlow::Break(None) => return,
@ -3149,7 +3150,7 @@ impl Editor {
to_insert,
}) = self.inlay_hint_cache.remove_excerpts(excerpts_removed)
{
self.splice_inlay_hints(to_remove, to_insert, cx);
self.splice_inlays(to_remove, to_insert, cx);
}
return;
}
@ -3172,7 +3173,7 @@ impl Editor {
ignore_debounce,
cx,
) {
self.splice_inlay_hints(to_remove, to_insert, cx);
self.splice_inlays(to_remove, to_insert, cx);
}
}
@ -3180,9 +3181,7 @@ impl Editor {
self.display_map
.read(cx)
.current_inlays()
.filter(move |inlay| {
Some(inlay.id) != self.copilot_state.suggestion.as_ref().map(|h| h.id)
})
.filter(move |inlay| matches!(inlay.id, InlayId::Hint(_)))
.cloned()
.collect()
}
@ -3253,7 +3252,7 @@ impl Editor {
}
}
fn splice_inlay_hints(
fn splice_inlays(
&self,
to_remove: Vec<InlayId>,
to_insert: Vec<Inlay>,
@ -4161,7 +4160,10 @@ impl Editor {
}
fn clear_copilot_suggestions(&mut self, cx: &mut ViewContext<Self>) {
self.copilot_state = Default::default();
if let Some(old_suggestion) = self.copilot_state.suggestion.take() {
self.splice_inlays(vec![old_suggestion.id], Vec::new(), cx);
}
self.copilot_state = CopilotState::default();
self.discard_copilot_suggestion(cx);
}

View file

@ -1255,7 +1255,7 @@ fn apply_hint_update(
editor.inlay_hint_cache.version += 1;
}
if displayed_inlays_changed {
editor.splice_inlay_hints(to_remove, to_insert, cx)
editor.splice_inlays(to_remove, to_insert, cx)
}
}