Skip to content

Commit

Permalink
Add fine-grained control for scrollbar diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Dec 25, 2024
1 parent 95911aa commit 4f1f668
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
9 changes: 7 additions & 2 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,13 @@
"search_results": true,
// Whether to show selected symbol occurrences in the scrollbar.
"selected_symbol": true,
// Whether to show diagnostic indicators in the scrollbar.
"diagnostics": true,
/// Which diagnostic indicators to show in the scrollbar.
/// "none": do not show any diagnostics
/// "error": show only errors
/// "warning": show only errors and warnings
/// "information": show only errors, warnings, and information
/// "all": show all diagnostics
"diagnostics": "all",
/// Forcefully enable or disable the scrollbar for each axis
"axes": {
/// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
Expand Down
26 changes: 22 additions & 4 deletions crates/editor/src/editor_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct Scrollbar {
pub git_diff: bool,
pub selected_symbol: bool,
pub search_results: bool,
pub diagnostics: bool,
pub diagnostics: ScrollbarDiagnostics,
pub cursors: bool,
pub axes: ScrollbarAxes,
}
Expand Down Expand Up @@ -150,6 +150,24 @@ pub struct ScrollbarAxes {
pub vertical: bool,
}

/// Which diagnostic indicators to show in the scrollbar.
///
/// Default: all
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ScrollbarDiagnostics {
/// Show all diagnostic levels: hint, information, warnings, error.
All,
/// Show only the following diagnostic levels: information, warning, error.
Information,
/// Show only the following diagnostic levels: warning, error.
Warning,
/// Show only the following diagnostic level: error.
Error,
/// Do not show diagnostics.
None,
}

/// The key to use for adding multiple cursors
///
/// Default: alt
Expand Down Expand Up @@ -348,10 +366,10 @@ pub struct ScrollbarContent {
///
/// Default: true
pub selected_symbol: Option<bool>,
/// Whether to show diagnostic indicators in the scrollbar.
/// Which diagnostic indicators to show in the scrollbar.
///
/// Default: true
pub diagnostics: Option<bool>,
/// Default: all
pub diagnostics: Option<ScrollbarDiagnostics>,
/// Whether to show cursor positions in the scrollbar.
///
/// Default: true
Expand Down
31 changes: 28 additions & 3 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
},
editor_settings::{
CurrentLineHighlight, DoubleClickInMultibuffer, MultiCursorModifier, ScrollBeyondLastLine,
ShowScrollbar,
ScrollbarDiagnostics, ShowScrollbar,
},
git::blame::{CommitDetails, GitBlame},
hover_popover::{
Expand Down Expand Up @@ -1207,7 +1207,7 @@ impl EditorElement {
(is_singleton && scrollbar_settings.selected_symbol && (editor.has_background_highlights::<DocumentHighlightRead>() || editor.has_background_highlights::<DocumentHighlightWrite>()))
||
// Diagnostics
(is_singleton && scrollbar_settings.diagnostics && snapshot.buffer_snapshot.has_diagnostics())
(is_singleton && scrollbar_settings.diagnostics != ScrollbarDiagnostics::None && snapshot.buffer_snapshot.has_diagnostics())
||
// Cursors out of sight
non_visible_cursors
Expand Down Expand Up @@ -4657,13 +4657,38 @@ impl EditorElement {
}
}

if scrollbar_settings.diagnostics {
if scrollbar_settings.diagnostics != ScrollbarDiagnostics::None {
let diagnostics = snapshot
.buffer_snapshot
.diagnostics_in_range::<_, Point>(
Point::zero()..max_point,
false,
)
// Don't show diagnostics the user doesn't care about
.filter(|diagnostic| {
match (
scrollbar_settings.diagnostics,
diagnostic.diagnostic.severity,
) {
(ScrollbarDiagnostics::All, _) => true,
(
ScrollbarDiagnostics::Error,
DiagnosticSeverity::ERROR,
) => true,
(
ScrollbarDiagnostics::Warning,
DiagnosticSeverity::ERROR
| DiagnosticSeverity::WARNING,
) => true,
(
ScrollbarDiagnostics::Information,
DiagnosticSeverity::ERROR
| DiagnosticSeverity::WARNING
| DiagnosticSeverity::INFORMATION,
) => true,
(_, _) => false,
}
})
// We want to sort by severity, in order to paint the most severe diagnostics last.
.sorted_by_key(|diagnostic| {
std::cmp::Reverse(diagnostic.diagnostic.severity)
Expand Down

0 comments on commit 4f1f668

Please sign in to comment.