on master help sign in
Add global error/warning count statusline element (#4569)
commit91ff903bf3867f112d242d6ecbe0b417b900656f authorGaurav Tyagi <grvtyagi22@gmail.com> dateTue 15 Nov 2022, 07:16 (4 years ago) parent1233c9a
3 files changed+48
book/src/configuration.md+1 helix-term/src/ui/statusline.rs+44 helix-view/src/editor.rs+3
book/src/configuration.md+1
@@ -102,6 +102,7 @@ The following statusline elements can be configured:
102102| `total-line-numbers` | The total line numbers of the opened file |
103103| `file-type` | The type of the opened file |
104104| `diagnostics` | The number of warnings and/or errors |
105+| `workspace-diagnostics` | The number of warnings and/or errors on workspace |
105106| `selections` | The number of active selections |
106107| `primary-selection-length` | The number of characters currently in primary selection |
107108| `position` | The cursor position |
helix-term/src/ui/statusline.rs+44
@@ -1,4 +1,5 @@
11use helix_core::{coords_at_pos, encoding, Position};
2+use helix_lsp::lsp::DiagnosticSeverity;
23use helix_view::{
34 document::{Mode, SCRATCH_BUFFER_NAME},
45 graphics::Rect,
@@ -141,6 +142,7 @@ where
141142 helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
142143 helix_view::editor::StatusLineElement::FileType => render_file_type,
143144 helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
145+ helix_view::editor::StatusLineElement::WorkspaceDiagnostics => render_workspace_diagnostics,
144146 helix_view::editor::StatusLineElement::Selections => render_selections,
145147 helix_view::editor::StatusLineElement::PrimarySelectionLength => {
146148 render_primary_selection_length
@@ -245,6 +247,48 @@ where
245247 }
246248}
247249
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+
248292fn render_selections<F>(context: &mut RenderContext, write: F)
249293where
250294 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
helix-view/src/editor.rs+3
@@ -325,6 +325,9 @@ pub enum StatusLineElement {
325325 /// A summary of the number of errors and warnings
326326 Diagnostics,
327327
328+ /// A summary of the number of errors and warnings on file and workspace
329+ WorkspaceDiagnostics,
330+
328331 /// The number of selections (cursors)
329332 Selections,
330333