Diagnostics small fixes (#28817)

Conrad Irwin created

- **Clear diagnostics cache when toggling warnings**
- **Fix focus when first adding excerpts**

Closes #ISSUE

Release Notes:

- N/A *or* Added/Fixed/Improved ...

Change summary

crates/diagnostics/src/diagnostics.rs | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

Detailed changes

crates/diagnostics/src/diagnostics.rs 🔗

@@ -209,6 +209,7 @@ impl ProjectDiagnosticsEditor {
         .detach();
         cx.observe_global_in::<IncludeWarnings>(window, |this, window, cx| {
             this.include_warnings = cx.global::<IncludeWarnings>().0;
+            this.diagnostics.clear();
             this.update_all_excerpts(window, cx);
         })
         .detach();
@@ -300,11 +301,8 @@ impl ProjectDiagnosticsEditor {
         }
     }
 
-    fn toggle_warnings(&mut self, _: &ToggleWarnings, window: &mut Window, cx: &mut Context<Self>) {
-        self.include_warnings = !self.include_warnings;
-        cx.set_global(IncludeWarnings(self.include_warnings));
-        self.update_all_excerpts(window, cx);
-        cx.notify();
+    fn toggle_warnings(&mut self, _: &ToggleWarnings, _: &mut Window, cx: &mut Context<Self>) {
+        cx.set_global(IncludeWarnings(!self.include_warnings));
     }
 
     fn focus_in(&mut self, window: &mut Window, cx: &mut Context<Self>) {
@@ -482,7 +480,10 @@ impl ProjectDiagnosticsEditor {
                             editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
                                 s.select_anchor_ranges([range_to_select]);
                             })
-                        })
+                        });
+                        if this.focus_handle.is_focused(window) {
+                            this.editor.read(cx).focus_handle(cx).focus(window);
+                        }
                     }
                 }