From 8bca9baf3cb371eb45023eb986b8730e21cf728c Mon Sep 17 00:00:00 2001
From: Kristóf Marussy <kristof@marussy.com>
Date: Mon, 25 Oct 2021 20:56:35 +0200
Subject: feat(web): show lint status on lint button

---
 language-web/src/main/js/editor/EditorButtons.tsx | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

(limited to 'language-web/src/main/js/editor/EditorButtons.tsx')

diff --git a/language-web/src/main/js/editor/EditorButtons.tsx b/language-web/src/main/js/editor/EditorButtons.tsx
index 9622475c..bd843dfe 100644
--- a/language-web/src/main/js/editor/EditorButtons.tsx
+++ b/language-web/src/main/js/editor/EditorButtons.tsx
@@ -1,16 +1,35 @@
+import type { Diagnostic } from '@codemirror/lint';
 import { observer } from 'mobx-react-lite';
 import Stack from '@mui/material/Stack';
 import ToggleButton from '@mui/material/ToggleButton';
 import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
 import CheckIcon from '@mui/icons-material/Check';
+import ErrorIcon from '@mui/icons-material/Error';
 import FormatListNumberedIcon from '@mui/icons-material/FormatListNumbered';
+import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
 import RedoIcon from '@mui/icons-material/Redo';
 import SearchIcon from '@mui/icons-material/Search';
 import UndoIcon from '@mui/icons-material/Undo';
+import WarningIcon from '@mui/icons-material/Warning';
 import React from 'react';
 
 import { useRootStore } from '../RootStore';
 
+// Exhastive switch as proven by TypeScript.
+// eslint-disable-next-line consistent-return
+function getLintIcon(severity: Diagnostic['severity'] | null) {
+  switch (severity) {
+    case 'error':
+      return <ErrorIcon fontSize="small" />;
+    case 'warning':
+      return <WarningIcon fontSize="small" />;
+    case 'info':
+      return <InfoOutlinedIcon fontSize="small" />;
+    case null:
+      return <CheckIcon fontSize="small" />;
+  }
+}
+
 export const EditorButtons = observer(() => {
   const { editorStore } = useRootStore();
 
@@ -61,10 +80,10 @@ export const EditorButtons = observer(() => {
         <ToggleButton
           selected={editorStore.showLintPanel}
           onClick={() => editorStore.toggleLintPanel()}
-          aria-label="Show errors and warnings"
+          aria-label={`${editorStore.errorCount} errors, ${editorStore.warningCount} warnings, ${editorStore.infoCount} info`}
           value="show-lint-panel"
         >
-          <CheckIcon fontSize="small" />
+          {getLintIcon(editorStore.highestDiagnosticLevel)}
         </ToggleButton>
       </ToggleButtonGroup>
     </Stack>
-- 
cgit v1.2.3-70-g09d2

