History

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))

Kirill Bulatov committed 2 years ago

Commit 146971f1 parent 34717803 files · +14 −12Browse files

Unified · Split

3 files
  1. crates/copilot_ui/src/copilot_button.rs +2 −2
  2. crates/editor/src/editor.rs +11 −9
  3. crates/editor/src/inlay_hint_cache.rs +1 −1
crates/copilot_ui/src/copilot_button.rs+2−2
@@ -149,7 +149,7 @@ impl CopilotButton { · 148 unmodified lines
149 pub fn build_copilot_menu(&mut self, cx: &mut ViewContext<Self>) -> View<ContextMenu> {149 pub fn build_copilot_menu(&mut self, cx: &mut ViewContext<Self>) -> View<ContextMenu> {
150 let fs = self.fs.clone();150 let fs = self.fs.clone();
151 151
152 return ContextMenu::build(cx, move |mut menu, cx| {152 ContextMenu::build(cx, move |mut menu, cx| {
153 if let Some(language) = self.language.clone() {153 if let Some(language) = self.language.clone() {
154 let fs = fs.clone();154 let fs = fs.clone();
155 let language_enabled =155 let language_enabled =
@@ -216,7 +216,7 @@ impl CopilotButton { · 60 unmodified lines
216 .boxed_clone(),216 .boxed_clone(),
217 )217 )
218 .action("Sign Out", SignOut.boxed_clone())218 .action("Sign Out", SignOut.boxed_clone())
219 });219 })
220 }220 }
221 221
222 pub fn update_enabled(&mut self, editor: View<Editor>, cx: &mut ViewContext<Self>) {222 pub fn update_enabled(&mut self, editor: View<Editor>, cx: &mut ViewContext<Self>) {
crates/editor/src/editor.rs+11−9
@@ -1215,6 +1215,7 @@ impl CodeActionsMenu { · 1214 unmodified lines
1215 }1215 }
1216}1216}
1217 1217
1218#[derive(Debug)]
1218pub(crate) struct CopilotState {1219pub(crate) struct CopilotState {
1219 excerpt_id: Option<ExcerptId>,1220 excerpt_id: Option<ExcerptId>,
1220 pending_refresh: Task<Option<()>>,1221 pending_refresh: Task<Option<()>>,
@@ -3114,7 +3115,7 @@ impl Editor { · 1893 unmodified lines
3114 (InvalidationStrategy::RefreshRequested, None)3115 (InvalidationStrategy::RefreshRequested, None)
3115 } else {3116 } else {
3116 self.inlay_hint_cache.clear();3117 self.inlay_hint_cache.clear();
3117 self.splice_inlay_hints(3118 self.splice_inlays(
3118 self.visible_inlay_hints(cx)3119 self.visible_inlay_hints(cx)
3119 .iter()3120 .iter()
3120 .map(|inlay| inlay.id)3121 .map(|inlay| inlay.id)
@@ -3136,7 +3137,7 @@ impl Editor { · 15 unmodified lines
3136 to_remove,3137 to_remove,
3137 to_insert,3138 to_insert,
3138 })) => {3139 })) => {
3139 self.splice_inlay_hints(to_remove, to_insert, cx);3140 self.splice_inlays(to_remove, to_insert, cx);
3140 return;3141 return;
3141 }3142 }
3142 ControlFlow::Break(None) => return,3143 ControlFlow::Break(None) => return,
@@ -3149,7 +3150,7 @@ impl Editor { · 6 unmodified lines
3149 to_insert,3150 to_insert,
3150 }) = self.inlay_hint_cache.remove_excerpts(excerpts_removed)3151 }) = self.inlay_hint_cache.remove_excerpts(excerpts_removed)
3151 {3152 {
3152 self.splice_inlay_hints(to_remove, to_insert, cx);3153 self.splice_inlays(to_remove, to_insert, cx);
3153 }3154 }
3154 return;3155 return;
3155 }3156 }
@@ -3172,7 +3173,7 @@ impl Editor { · 16 unmodified lines
3172 ignore_debounce,3173 ignore_debounce,
3173 cx,3174 cx,
3174 ) {3175 ) {
3175 self.splice_inlay_hints(to_remove, to_insert, cx);3176 self.splice_inlays(to_remove, to_insert, cx);
3176 }3177 }
3177 }3178 }
3178 3179
@@ -3180,9 +3181,7 @@ impl Editor { · 1 unmodified line
3180 self.display_map3181 self.display_map
3181 .read(cx)3182 .read(cx)
3182 .current_inlays()3183 .current_inlays()
3183 .filter(move |inlay| {3184 .filter(move |inlay| matches!(inlay.id, InlayId::Hint(_)))
3184 Some(inlay.id) != self.copilot_state.suggestion.as_ref().map(|h| h.id)
3185 })
3186 .cloned()3185 .cloned()
3187 .collect()3186 .collect()
3188 }3187 }
@@ -3253,7 +3252,7 @@ impl Editor { · 64 unmodified lines
3253 }3252 }
3254 }3253 }
3255 3254
3256 fn splice_inlay_hints(3255 fn splice_inlays(
3257 &self,3256 &self,
3258 to_remove: Vec<InlayId>,3257 to_remove: Vec<InlayId>,
3259 to_insert: Vec<Inlay>,3258 to_insert: Vec<Inlay>,
@@ -4161,7 +4160,10 @@ impl Editor { · 901 unmodified lines
4161 }4160 }
4162 4161
4163 fn clear_copilot_suggestions(&mut self, cx: &mut ViewContext<Self>) {4162 fn clear_copilot_suggestions(&mut self, cx: &mut ViewContext<Self>) {
4164 self.copilot_state = Default::default();4163 if let Some(old_suggestion) = self.copilot_state.suggestion.take() {
4164 self.splice_inlays(vec![old_suggestion.id], Vec::new(), cx);
4165 }
4166 self.copilot_state = CopilotState::default();
4165 self.discard_copilot_suggestion(cx);4167 self.discard_copilot_suggestion(cx);
4166 }4168 }
4167 4169
crates/editor/src/inlay_hint_cache.rs+1−1
@@ -1255,7 +1255,7 @@ fn apply_hint_update( · 1254 unmodified lines
1255 editor.inlay_hint_cache.version += 1;1255 editor.inlay_hint_cache.version += 1;
1256 }1256 }
1257 if displayed_inlays_changed {1257 if displayed_inlays_changed {
1258 editor.splice_inlay_hints(to_remove, to_insert, cx)1258 editor.splice_inlays(to_remove, to_insert, cx)
1259 }1259 }
1260}1260}
1261 1261