From 8bca9baf3cb371eb45023eb986b8730e21cf728c Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Mon, 25 Oct 2021 20:56:35 +0200 Subject: feat(web): show lint status on lint button --- language-web/src/main/js/editor/EditorStore.ts | 45 +++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'language-web/src/main/js/editor/EditorStore.ts') diff --git a/language-web/src/main/js/editor/EditorStore.ts b/language-web/src/main/js/editor/EditorStore.ts index 31bb0a11..32fe6fd1 100644 --- a/language-web/src/main/js/editor/EditorStore.ts +++ b/language-web/src/main/js/editor/EditorStore.ts @@ -14,7 +14,11 @@ import { undoDepth, } from '@codemirror/history'; import { indentOnInput } from '@codemirror/language'; -import { lintKeymap } from '@codemirror/lint'; +import { + Diagnostic, + lintKeymap, + setDiagnostics, +} from '@codemirror/lint'; import { bracketMatching } from '@codemirror/matchbrackets'; import { rectangularSelection } from '@codemirror/rectangular-selection'; import { searchConfig, searchKeymap } from '@codemirror/search'; @@ -58,6 +62,12 @@ export class EditorStore { showLintPanel = false; + errorCount = 0; + + warningCount = 0; + + infoCount = 0; + readonly defaultDispatcher = (tr: Transaction): void => { this.onTransaction(tr); }; @@ -153,6 +163,39 @@ export class EditorStore { }); } + updateDiagnostics(diagnostics: Diagnostic[]): void { + this.dispatch(setDiagnostics(this.state, diagnostics)); + this.errorCount = 0; + this.warningCount = 0; + this.infoCount = 0; + diagnostics.forEach(({ severity }) => { + switch (severity) { + case 'error': + this.errorCount += 1; + break; + case 'warning': + this.warningCount += 1; + break; + case 'info': + this.infoCount += 1; + break; + } + }); + } + + get highestDiagnosticLevel(): Diagnostic['severity'] | null { + if (this.errorCount > 0) { + return 'error'; + } + if (this.warningCount > 0) { + return 'warning'; + } + if (this.infoCount > 0) { + return 'info'; + } + return null; + } + /** * @returns `true` if there is history to undo */ -- cgit v1.2.3-70-g09d2