feat: attempt at getting config option to disable diagnostics working

This commit is contained in:
Nikita Revenco 2024-12-09 13:57:54 +00:00
parent 8271a35be2
commit be3dea5468
4 changed files with 17 additions and 14 deletions

View file

@ -17,7 +17,9 @@ pub(super) fn register_hooks(_handlers: &Handlers) {
});
register_hook!(move |event: &mut OnModeSwitch<'_, '_>| {
for (view, _) in event.cx.editor.tree.views_mut() {
view.diagnostics_handler.active = event.new_mode != Mode::Insert;
view.diagnostics_handler
.active
.set(event.new_mode != Mode::Insert);
}
Ok(())
});

View file

@ -191,7 +191,11 @@ impl EditorView {
}
let config = doc.config.load();
if editor.config().enable_diagnostics {
// view.diagnostics_handler
// .active
// .set(config.enable_diagnostics);
if config.enable_diagnostics {
let width = view.inner_width(doc);
let enable_cursor_line = view
.diagnostics_handler
@ -235,7 +239,7 @@ impl EditorView {
if config.inline_diagnostics.disabled()
&& config.end_of_line_diagnostics == DiagnosticFilter::Disable
&& editor.config().enable_diagnostics
&& config.enable_diagnostics
{
Self::render_diagnostics(doc, view, inner, surface, theme);
}

View file

@ -1649,18 +1649,15 @@ impl Editor {
}
Action::HorizontalSplit | Action::VerticalSplit => {
// copy the current view, unless there is no view yet
let config = self.config();
let gutters = config.gutters.clone();
let enable_diagnostics = config.enable_diagnostics;
let view = self
.tree
.try_get(self.tree.focus)
.filter(|v| id == v.doc) // Different Document
.cloned()
.unwrap_or_else(|| {
View::new(
id,
self.config().gutters.clone(),
self.config().enable_diagnostics,
)
});
.unwrap_or_else(|| View::new(id, gutters, enable_diagnostics));
let view_id = self.tree.split(
view,
match action {

View file

@ -59,7 +59,7 @@ pub struct DiagnosticsHandler {
generation: Cell<usize>,
last_doc: Cell<DocumentId>,
last_cursor_line: Cell<usize>,
pub active: bool,
pub active: Cell<bool>,
pub events: Sender<DiagnosticEvent>,
}
@ -69,7 +69,7 @@ pub struct DiagnosticsHandler {
// but to fix that larger architecutre changes are needed
impl Clone for DiagnosticsHandler {
fn clone(&self) -> Self {
Self::new(self.active)
Self::new(self.active.take())
}
}
@ -88,7 +88,7 @@ impl DiagnosticsHandler {
events,
last_doc: Cell::new(DocumentId(NonZeroUsize::new(usize::MAX).unwrap())),
last_cursor_line: Cell::new(usize::MAX),
active: enable_diagnostics,
active: true,
}
}
}
@ -106,7 +106,7 @@ impl DiagnosticsHandler {
}
pub fn show_cursorline_diagnostics(&self, doc: &Document, view: ViewId) -> bool {
if !self.active {
if !self.active.take() {
return false;
}
let cursor_line = doc