Allow dumping the project diagnostic view's state as JSON

Also, improve DebugElements action so that it shows the JSON in an editor.

Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-04-11 19:51:46 -07:00
parent 54d49c13d9
commit 949fbe7cd3
9 changed files with 116 additions and 42 deletions

View file

@ -8,13 +8,15 @@ use editor::{
highlight_diagnostic_message, Editor, ExcerptId, MultiBuffer, ToOffset,
};
use gpui::{
actions, elements::*, fonts::TextStyle, AnyViewHandle, AppContext, Entity, ModelHandle,
MutableAppContext, RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
actions, elements::*, fonts::TextStyle, serde_json, AnyViewHandle, AppContext, Entity,
ModelHandle, MutableAppContext, RenderContext, Task, View, ViewContext, ViewHandle,
WeakViewHandle,
};
use language::{
Bias, Buffer, Diagnostic, DiagnosticEntry, DiagnosticSeverity, Point, Selection, SelectionGoal,
};
use project::{DiagnosticSummary, Project, ProjectPath};
use serde_json::json;
use settings::Settings;
use std::{
any::{Any, TypeId},
@ -90,6 +92,31 @@ impl View for ProjectDiagnosticsEditor {
cx.focus(&self.editor);
}
}
fn debug_json(&self, cx: &AppContext) -> serde_json::Value {
let project = self.project.read(cx);
json!({
"project": json!({
"language_servers": project.language_server_statuses().collect::<Vec<_>>(),
"summary": project.diagnostic_summary(cx),
}),
"summary": self.summary,
"paths_to_update": self.paths_to_update.iter().map(|path|
path.path.to_string_lossy()
).collect::<Vec<_>>(),
"paths_states": self.path_states.iter().map(|state|
json!({
"path": state.path.path.to_string_lossy(),
"groups": state.diagnostic_groups.iter().map(|group|
json!({
"block_count": group.blocks.len(),
"excerpt_count": group.excerpts.len(),
})
).collect::<Vec<_>>(),
})
).collect::<Vec<_>>(),
})
}
}
impl ProjectDiagnosticsEditor {