on master help sign in
Add global error/warning count statusline element (#4569)
91ff903Gaurav Tyagi
book/src/configuration.md+1
@@ -102,6 +102,7 @@ The following statusline elements can be configured:
102| `total-line-numbers` | The total line numbers of the opened file |
102| `total-line-numbers` | The total line numbers of the opened file |
103| `file-type` | The type of the opened file |
103| `file-type` | The type of the opened file |
104| `diagnostics` | The number of warnings and/or errors |
104| `diagnostics` | The number of warnings and/or errors |
105+| `workspace-diagnostics` | The number of warnings and/or errors on workspace |
105| `selections` | The number of active selections |
106| `selections` | The number of active selections |
106| `primary-selection-length` | The number of characters currently in primary selection |
107| `primary-selection-length` | The number of characters currently in primary selection |
107| `position` | The cursor position |
108| `position` | The cursor position |
helix-term/src/ui/statusline.rs+44
@@ -1,4 +1,5 @@
1use helix_core::{coords_at_pos, encoding, Position};
1use helix_core::{coords_at_pos, encoding, Position};
2+use helix_lsp::lsp::DiagnosticSeverity;
2use helix_view::{
3use helix_view::{
3 document::{Mode, SCRATCH_BUFFER_NAME},
4 document::{Mode, SCRATCH_BUFFER_NAME},
4 graphics::Rect,
5 graphics::Rect,
@@ -141,6 +142,7 @@ where
141 helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
142 helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
142 helix_view::editor::StatusLineElement::FileType => render_file_type,
143 helix_view::editor::StatusLineElement::FileType => render_file_type,
143 helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
144 helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
145+ helix_view::editor::StatusLineElement::WorkspaceDiagnostics => render_workspace_diagnostics,
144 helix_view::editor::StatusLineElement::Selections => render_selections,
146 helix_view::editor::StatusLineElement::Selections => render_selections,
145 helix_view::editor::StatusLineElement::PrimarySelectionLength => {
147 helix_view::editor::StatusLineElement::PrimarySelectionLength => {
146 render_primary_selection_length
148 render_primary_selection_length
@@ -245,6 +247,48 @@ where
245 }
247 }
246}
248}
247
249
250+fn render_workspace_diagnostics<F>(context: &mut RenderContext, write: F)
251+where
252+ F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
253+{
254+ let (warnings, errors) =
255+ context
256+ .editor
257+ .diagnostics
258+ .values()
259+ .flatten()
260+ .fold((0, 0), |mut counts, diag| {
261+ match diag.severity {
262+ Some(DiagnosticSeverity::WARNING) => counts.0 += 1,
263+ Some(DiagnosticSeverity::ERROR) | None => counts.1 += 1,
264+ _ => {}
265+ }
266+ counts
267+ });
268+
269+ if warnings > 0 || errors > 0 {
270+ write(context, format!(" {} ", "W"), None);
271+ }
272+
273+ if warnings > 0 {
274+ write(
275+ context,
276+ "●".to_string(),
277+ Some(context.editor.theme.get("warning")),
278+ );
279+ write(context, format!(" {} ", warnings), None);
280+ }
281+
282+ if errors > 0 {
283+ write(
284+ context,
285+ "●".to_string(),
286+ Some(context.editor.theme.get("error")),
287+ );
288+ write(context, format!(" {} ", errors), None);
289+ }
290+}
291+
248fn render_selections<F>(context: &mut RenderContext, write: F)
292fn render_selections<F>(context: &mut RenderContext, write: F)
249where
293where
250 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
294 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
helix-view/src/editor.rs+3
@@ -325,6 +325,9 @@ pub enum StatusLineElement {
325 /// A summary of the number of errors and warnings
325 /// A summary of the number of errors and warnings
326 Diagnostics,
326 Diagnostics,
327
327
328+ /// A summary of the number of errors and warnings on file and workspace
329+ WorkspaceDiagnostics,
330+
328 /// The number of selections (cursors)
331 /// The number of selections (cursors)
329 Selections,
332 Selections,
330
333