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 27, 2024
1 parent d71180a commit 40c30a9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
6 changes: 6 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@
"selected_symbol": true,
// Whether to show diagnostic indicators in the scrollbar.
"diagnostics": true,
// Which diagnostic indicator levels to show in the scrollbar, if indicators are enabled:
// - "error": show only errors
// - "warning": show only errors and warnings
// - "information": show only errors, warnings, and information
// - "all": show all diagnostics
"diagnostic_level": "all",
/// Forcefully enable or disable the scrollbar for each axis
"axes": {
/// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
Expand Down
21 changes: 21 additions & 0 deletions crates/editor/src/editor_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub struct Scrollbar {
pub selected_symbol: bool,
pub search_results: bool,
pub diagnostics: bool,
pub diagnostic_level: ScrollbarDiagnosticLevel,
pub cursors: bool,
pub axes: ScrollbarAxes,
}
Expand Down Expand Up @@ -150,6 +151,22 @@ pub struct ScrollbarAxes {
pub vertical: bool,
}

/// Which diagnostic indicator levels to show in the scrollbar.
///
/// Default: all
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum ScrollbarDiagnosticLevel {
/// 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,
}

/// The key to use for adding multiple cursors
///
/// Default: alt
Expand Down Expand Up @@ -352,6 +369,10 @@ pub struct ScrollbarContent {
///
/// Default: true
pub diagnostics: Option<bool>,
/// Which diagnostic indicators to show in the scrollbar.
///
/// Default: all
pub diagnostic_level: Option<ScrollbarDiagnosticLevel>,
/// Whether to show cursor positions in the scrollbar.
///
/// Default: true
Expand Down
27 changes: 26 additions & 1 deletion 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,
ScrollbarDiagnosticLevel, ShowScrollbar,
},
git::blame::{CommitDetails, GitBlame},
hover_popover::{
Expand Down Expand Up @@ -4664,6 +4664,31 @@ impl EditorElement {
Point::zero()..max_point,
false,
)
// Don't show diagnostics the user doesn't care about
.filter(|diagnostic| {
match (
scrollbar_settings.diagnostic_level,
diagnostic.diagnostic.severity,
) {
(ScrollbarDiagnosticLevel::All, _) => true,
(
ScrollbarDiagnosticLevel::Error,
DiagnosticSeverity::ERROR,
) => true,
(
ScrollbarDiagnosticLevel::Warning,
DiagnosticSeverity::ERROR
| DiagnosticSeverity::WARNING,
) => true,
(
ScrollbarDiagnosticLevel::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 40c30a9

Please sign in to comment.