feat: add command to toggle diagnostics does not work
This commit is contained in:
parent
28953ef40f
commit
0dce39e0df
3 changed files with 35 additions and 0 deletions
|
@ -1928,6 +1928,24 @@ fn set_option(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn toggle_diagnostics(
|
||||
cx: &mut compositor::Context,
|
||||
args: &[Cow<str>],
|
||||
event: PromptEvent,
|
||||
) -> anyhow::Result<()> {
|
||||
if event != PromptEvent::Validate {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
ensure!(args.is_empty(), ":toggle-diagnostics takes no arguments");
|
||||
|
||||
let (view, _) = current!(cx.editor);
|
||||
|
||||
view.diagnostics_handler.toggle_diagnostics();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Toggle boolean config option at runtime. Access nested values by dot
|
||||
/// syntax, for example to toggle smart case search, use `:toggle search.smart-
|
||||
/// case`.
|
||||
|
@ -3149,6 +3167,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
|
|||
fun: read,
|
||||
signature: CommandSignature::positional(&[completers::filename]),
|
||||
},
|
||||
TypableCommand {
|
||||
name: "toggle-diagnostics",
|
||||
aliases: &["td"],
|
||||
doc: "Toggle Diagnostics",
|
||||
fun: toggle_diagnostics,
|
||||
signature: CommandSignature::all(completers::register)
|
||||
}
|
||||
];
|
||||
|
||||
pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
|
||||
|
|
|
@ -1049,6 +1049,8 @@ pub struct Editor {
|
|||
pub debugger_events: SelectAll<UnboundedReceiverStream<dap::Payload>>,
|
||||
pub breakpoints: HashMap<PathBuf, Vec<Breakpoint>>,
|
||||
|
||||
pub show_diagnostics: bool,
|
||||
|
||||
pub syn_loader: Arc<ArcSwap<syntax::Loader>>,
|
||||
pub theme_loader: Arc<theme::Loader>,
|
||||
/// last_theme is used for theme previews. We store the current theme here,
|
||||
|
@ -1195,6 +1197,7 @@ impl Editor {
|
|||
breakpoints: HashMap::new(),
|
||||
syn_loader,
|
||||
theme_loader,
|
||||
show_diagnostics: true,
|
||||
last_theme: None,
|
||||
last_selection: None,
|
||||
registers: Registers::new(Box::new(arc_swap::access::Map::new(
|
||||
|
@ -1328,6 +1331,10 @@ impl Editor {
|
|||
self.set_theme_impl(theme, ThemeAction::Set);
|
||||
}
|
||||
|
||||
pub fn toggle_diagnostics(&mut self) {
|
||||
self.show_diagnostics = !self.show_diagnostics;
|
||||
}
|
||||
|
||||
fn set_theme_impl(&mut self, theme: Theme, preview: ThemeAction) {
|
||||
// `ui.selection` is the only scope required to be able to render a theme.
|
||||
if theme.find_scope_index_exact("ui.selection").is_none() {
|
||||
|
|
|
@ -94,6 +94,9 @@ impl DiagnosticsHandler {
|
|||
}
|
||||
|
||||
impl DiagnosticsHandler {
|
||||
pub fn toggle_diagnostics(&mut self) {
|
||||
self.active = !self.active;
|
||||
}
|
||||
pub fn immediately_show_diagnostic(&self, doc: &Document, view: ViewId) {
|
||||
self.last_doc.set(doc.id());
|
||||
let cursor_line = doc
|
||||
|
|
Loading…
Add table
Reference in a new issue