Implement session-global include_warnings in the diagnostic item (#21618)
Release Notes: - Make the include warnings toggle in the diagnostic tab global for a zed session.
This commit is contained in:
parent
aff17322f3
commit
cf4e847c62
2 changed files with 61 additions and 9 deletions
|
@ -16,8 +16,8 @@ use editor::{
|
||||||
};
|
};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, svg, AnyElement, AnyView, AppContext, Context, EventEmitter, FocusHandle,
|
actions, div, svg, AnyElement, AnyView, AppContext, Context, EventEmitter, FocusHandle,
|
||||||
FocusableView, HighlightStyle, InteractiveElement, IntoElement, Model, ParentElement, Render,
|
FocusableView, Global, HighlightStyle, InteractiveElement, IntoElement, Model, ParentElement,
|
||||||
SharedString, Styled, StyledText, Subscription, Task, View, ViewContext, VisualContext,
|
Render, SharedString, Styled, StyledText, Subscription, Task, View, ViewContext, VisualContext,
|
||||||
WeakView, WindowContext,
|
WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
use language::{
|
use language::{
|
||||||
|
@ -46,6 +46,9 @@ use workspace::{
|
||||||
|
|
||||||
actions!(diagnostics, [Deploy, ToggleWarnings]);
|
actions!(diagnostics, [Deploy, ToggleWarnings]);
|
||||||
|
|
||||||
|
struct IncludeWarnings(bool);
|
||||||
|
impl Global for IncludeWarnings {}
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
ProjectDiagnosticsSettings::register(cx);
|
ProjectDiagnosticsSettings::register(cx);
|
||||||
cx.observe_new_views(ProjectDiagnosticsEditor::register)
|
cx.observe_new_views(ProjectDiagnosticsEditor::register)
|
||||||
|
@ -117,6 +120,7 @@ impl ProjectDiagnosticsEditor {
|
||||||
|
|
||||||
fn new_with_context(
|
fn new_with_context(
|
||||||
context: u32,
|
context: u32,
|
||||||
|
include_warnings: bool,
|
||||||
project_handle: Model<Project>,
|
project_handle: Model<Project>,
|
||||||
workspace: WeakView<Workspace>,
|
workspace: WeakView<Workspace>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
|
@ -186,19 +190,24 @@ impl ProjectDiagnosticsEditor {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
cx.observe_global::<IncludeWarnings>(|this, cx| {
|
||||||
|
this.include_warnings = cx.global::<IncludeWarnings>().0;
|
||||||
|
this.update_all_excerpts(cx);
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
let project = project_handle.read(cx);
|
let project = project_handle.read(cx);
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
project: project_handle.clone(),
|
project: project_handle.clone(),
|
||||||
context,
|
context,
|
||||||
summary: project.diagnostic_summary(false, cx),
|
summary: project.diagnostic_summary(false, cx),
|
||||||
|
include_warnings,
|
||||||
workspace,
|
workspace,
|
||||||
excerpts,
|
excerpts,
|
||||||
focus_handle,
|
focus_handle,
|
||||||
editor,
|
editor,
|
||||||
path_states: Default::default(),
|
path_states: Default::default(),
|
||||||
paths_to_update: Default::default(),
|
paths_to_update: Default::default(),
|
||||||
include_warnings: ProjectDiagnosticsSettings::get_global(cx).include_warnings,
|
|
||||||
update_excerpts_task: None,
|
update_excerpts_task: None,
|
||||||
_subscription: project_event_subscription,
|
_subscription: project_event_subscription,
|
||||||
};
|
};
|
||||||
|
@ -243,11 +252,13 @@ impl ProjectDiagnosticsEditor {
|
||||||
|
|
||||||
fn new(
|
fn new(
|
||||||
project_handle: Model<Project>,
|
project_handle: Model<Project>,
|
||||||
|
include_warnings: bool,
|
||||||
workspace: WeakView<Workspace>,
|
workspace: WeakView<Workspace>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_with_context(
|
Self::new_with_context(
|
||||||
editor::DEFAULT_MULTIBUFFER_CONTEXT,
|
editor::DEFAULT_MULTIBUFFER_CONTEXT,
|
||||||
|
include_warnings,
|
||||||
project_handle,
|
project_handle,
|
||||||
workspace,
|
workspace,
|
||||||
cx,
|
cx,
|
||||||
|
@ -259,8 +270,19 @@ impl ProjectDiagnosticsEditor {
|
||||||
workspace.activate_item(&existing, true, true, cx);
|
workspace.activate_item(&existing, true, true, cx);
|
||||||
} else {
|
} else {
|
||||||
let workspace_handle = cx.view().downgrade();
|
let workspace_handle = cx.view().downgrade();
|
||||||
|
|
||||||
|
let include_warnings = match cx.try_global::<IncludeWarnings>() {
|
||||||
|
Some(include_warnings) => include_warnings.0,
|
||||||
|
None => ProjectDiagnosticsSettings::get_global(cx).include_warnings,
|
||||||
|
};
|
||||||
|
|
||||||
let diagnostics = cx.new_view(|cx| {
|
let diagnostics = cx.new_view(|cx| {
|
||||||
ProjectDiagnosticsEditor::new(workspace.project().clone(), workspace_handle, cx)
|
ProjectDiagnosticsEditor::new(
|
||||||
|
workspace.project().clone(),
|
||||||
|
include_warnings,
|
||||||
|
workspace_handle,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
workspace.add_item_to_active_pane(Box::new(diagnostics), None, true, cx);
|
workspace.add_item_to_active_pane(Box::new(diagnostics), None, true, cx);
|
||||||
}
|
}
|
||||||
|
@ -268,6 +290,7 @@ impl ProjectDiagnosticsEditor {
|
||||||
|
|
||||||
fn toggle_warnings(&mut self, _: &ToggleWarnings, cx: &mut ViewContext<Self>) {
|
fn toggle_warnings(&mut self, _: &ToggleWarnings, cx: &mut ViewContext<Self>) {
|
||||||
self.include_warnings = !self.include_warnings;
|
self.include_warnings = !self.include_warnings;
|
||||||
|
cx.set_global(IncludeWarnings(self.include_warnings));
|
||||||
self.update_all_excerpts(cx);
|
self.update_all_excerpts(cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
@ -740,7 +763,12 @@ impl Item for ProjectDiagnosticsEditor {
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
Some(cx.new_view(|cx| {
|
Some(cx.new_view(|cx| {
|
||||||
ProjectDiagnosticsEditor::new(self.project.clone(), self.workspace.clone(), cx)
|
ProjectDiagnosticsEditor::new(
|
||||||
|
self.project.clone(),
|
||||||
|
self.include_warnings,
|
||||||
|
self.workspace.clone(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,13 @@ async fn test_diagnostics(cx: &mut TestAppContext) {
|
||||||
|
|
||||||
// Open the project diagnostics view while there are already diagnostics.
|
// Open the project diagnostics view while there are already diagnostics.
|
||||||
let view = window.build_view(cx, |cx| {
|
let view = window.build_view(cx, |cx| {
|
||||||
ProjectDiagnosticsEditor::new_with_context(1, project.clone(), workspace.downgrade(), cx)
|
ProjectDiagnosticsEditor::new_with_context(
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
project.clone(),
|
||||||
|
workspace.downgrade(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
let editor = view.update(cx, |view, _| view.editor.clone());
|
let editor = view.update(cx, |view, _| view.editor.clone());
|
||||||
|
|
||||||
|
@ -459,7 +465,13 @@ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {
|
||||||
let workspace = window.root(cx).unwrap();
|
let workspace = window.root(cx).unwrap();
|
||||||
|
|
||||||
let view = window.build_view(cx, |cx| {
|
let view = window.build_view(cx, |cx| {
|
||||||
ProjectDiagnosticsEditor::new_with_context(1, project.clone(), workspace.downgrade(), cx)
|
ProjectDiagnosticsEditor::new_with_context(
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
project.clone(),
|
||||||
|
workspace.downgrade(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
let editor = view.update(cx, |view, _| view.editor.clone());
|
let editor = view.update(cx, |view, _| view.editor.clone());
|
||||||
|
|
||||||
|
@ -720,7 +732,13 @@ async fn test_random_diagnostics(cx: &mut TestAppContext, mut rng: StdRng) {
|
||||||
let workspace = window.root(cx).unwrap();
|
let workspace = window.root(cx).unwrap();
|
||||||
|
|
||||||
let mutated_view = window.build_view(cx, |cx| {
|
let mutated_view = window.build_view(cx, |cx| {
|
||||||
ProjectDiagnosticsEditor::new_with_context(1, project.clone(), workspace.downgrade(), cx)
|
ProjectDiagnosticsEditor::new_with_context(
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
project.clone(),
|
||||||
|
workspace.downgrade(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
|
@ -816,7 +834,13 @@ async fn test_random_diagnostics(cx: &mut TestAppContext, mut rng: StdRng) {
|
||||||
|
|
||||||
log::info!("constructing reference diagnostics view");
|
log::info!("constructing reference diagnostics view");
|
||||||
let reference_view = window.build_view(cx, |cx| {
|
let reference_view = window.build_view(cx, |cx| {
|
||||||
ProjectDiagnosticsEditor::new_with_context(1, project.clone(), workspace.downgrade(), cx)
|
ProjectDiagnosticsEditor::new_with_context(
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
project.clone(),
|
||||||
|
workspace.downgrade(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
cx.run_until_parked();
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue