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:
parent
347178039c
commit
146971fb02
3 changed files with 14 additions and 12 deletions
|
@ -149,7 +149,7 @@ impl CopilotButton {
|
||||||
pub fn build_copilot_menu(&mut self, cx: &mut ViewContext<Self>) -> View<ContextMenu> {
|
pub fn build_copilot_menu(&mut self, cx: &mut ViewContext<Self>) -> View<ContextMenu> {
|
||||||
let fs = self.fs.clone();
|
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() {
|
if let Some(language) = self.language.clone() {
|
||||||
let fs = fs.clone();
|
let fs = fs.clone();
|
||||||
let language_enabled =
|
let language_enabled =
|
||||||
|
@ -216,7 +216,7 @@ impl CopilotButton {
|
||||||
.boxed_clone(),
|
.boxed_clone(),
|
||||||
)
|
)
|
||||||
.action("Sign Out", SignOut.boxed_clone())
|
.action("Sign Out", SignOut.boxed_clone())
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_enabled(&mut self, editor: View<Editor>, cx: &mut ViewContext<Self>) {
|
pub fn update_enabled(&mut self, editor: View<Editor>, cx: &mut ViewContext<Self>) {
|
||||||
|
|
|
@ -1215,6 +1215,7 @@ impl CodeActionsMenu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) struct CopilotState {
|
pub(crate) struct CopilotState {
|
||||||
excerpt_id: Option<ExcerptId>,
|
excerpt_id: Option<ExcerptId>,
|
||||||
pending_refresh: Task<Option<()>>,
|
pending_refresh: Task<Option<()>>,
|
||||||
|
@ -3114,7 +3115,7 @@ impl Editor {
|
||||||
(InvalidationStrategy::RefreshRequested, None)
|
(InvalidationStrategy::RefreshRequested, None)
|
||||||
} else {
|
} else {
|
||||||
self.inlay_hint_cache.clear();
|
self.inlay_hint_cache.clear();
|
||||||
self.splice_inlay_hints(
|
self.splice_inlays(
|
||||||
self.visible_inlay_hints(cx)
|
self.visible_inlay_hints(cx)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|inlay| inlay.id)
|
.map(|inlay| inlay.id)
|
||||||
|
@ -3136,7 +3137,7 @@ impl Editor {
|
||||||
to_remove,
|
to_remove,
|
||||||
to_insert,
|
to_insert,
|
||||||
})) => {
|
})) => {
|
||||||
self.splice_inlay_hints(to_remove, to_insert, cx);
|
self.splice_inlays(to_remove, to_insert, cx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ControlFlow::Break(None) => return,
|
ControlFlow::Break(None) => return,
|
||||||
|
@ -3149,7 +3150,7 @@ impl Editor {
|
||||||
to_insert,
|
to_insert,
|
||||||
}) = self.inlay_hint_cache.remove_excerpts(excerpts_removed)
|
}) = 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;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -3172,7 +3173,7 @@ impl Editor {
|
||||||
ignore_debounce,
|
ignore_debounce,
|
||||||
cx,
|
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
|
self.display_map
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.current_inlays()
|
.current_inlays()
|
||||||
.filter(move |inlay| {
|
.filter(move |inlay| matches!(inlay.id, InlayId::Hint(_)))
|
||||||
Some(inlay.id) != self.copilot_state.suggestion.as_ref().map(|h| h.id)
|
|
||||||
})
|
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -3253,7 +3252,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn splice_inlay_hints(
|
fn splice_inlays(
|
||||||
&self,
|
&self,
|
||||||
to_remove: Vec<InlayId>,
|
to_remove: Vec<InlayId>,
|
||||||
to_insert: Vec<Inlay>,
|
to_insert: Vec<Inlay>,
|
||||||
|
@ -4161,7 +4160,10 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_copilot_suggestions(&mut self, cx: &mut ViewContext<Self>) {
|
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);
|
self.discard_copilot_suggestion(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1255,7 +1255,7 @@ fn apply_hint_update(
|
||||||
editor.inlay_hint_cache.version += 1;
|
editor.inlay_hint_cache.version += 1;
|
||||||
}
|
}
|
||||||
if displayed_inlays_changed {
|
if displayed_inlays_changed {
|
||||||
editor.splice_inlay_hints(to_remove, to_insert, cx)
|
editor.splice_inlays(to_remove, to_insert, cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue