@@ -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,