diff options
Diffstat (limited to 'language-web/src/main/js/editor/EditorStore.ts')
-rw-r--r-- | language-web/src/main/js/editor/EditorStore.ts | 45 |
1 files changed, 44 insertions, 1 deletions
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 { | |||
14 | undoDepth, | 14 | undoDepth, |
15 | } from '@codemirror/history'; | 15 | } from '@codemirror/history'; |
16 | import { indentOnInput } from '@codemirror/language'; | 16 | import { indentOnInput } from '@codemirror/language'; |
17 | import { lintKeymap } from '@codemirror/lint'; | 17 | import { |
18 | Diagnostic, | ||
19 | lintKeymap, | ||
20 | setDiagnostics, | ||
21 | } from '@codemirror/lint'; | ||
18 | import { bracketMatching } from '@codemirror/matchbrackets'; | 22 | import { bracketMatching } from '@codemirror/matchbrackets'; |
19 | import { rectangularSelection } from '@codemirror/rectangular-selection'; | 23 | import { rectangularSelection } from '@codemirror/rectangular-selection'; |
20 | import { searchConfig, searchKeymap } from '@codemirror/search'; | 24 | import { searchConfig, searchKeymap } from '@codemirror/search'; |
@@ -58,6 +62,12 @@ export class EditorStore { | |||
58 | 62 | ||
59 | showLintPanel = false; | 63 | showLintPanel = false; |
60 | 64 | ||
65 | errorCount = 0; | ||
66 | |||
67 | warningCount = 0; | ||
68 | |||
69 | infoCount = 0; | ||
70 | |||
61 | readonly defaultDispatcher = (tr: Transaction): void => { | 71 | readonly defaultDispatcher = (tr: Transaction): void => { |
62 | this.onTransaction(tr); | 72 | this.onTransaction(tr); |
63 | }; | 73 | }; |
@@ -153,6 +163,39 @@ export class EditorStore { | |||
153 | }); | 163 | }); |
154 | } | 164 | } |
155 | 165 | ||
166 | updateDiagnostics(diagnostics: Diagnostic[]): void { | ||
167 | this.dispatch(setDiagnostics(this.state, diagnostics)); | ||
168 | this.errorCount = 0; | ||
169 | this.warningCount = 0; | ||
170 | this.infoCount = 0; | ||
171 | diagnostics.forEach(({ severity }) => { | ||
172 | switch (severity) { | ||
173 | case 'error': | ||
174 | this.errorCount += 1; | ||
175 | break; | ||
176 | case 'warning': | ||
177 | this.warningCount += 1; | ||
178 | break; | ||
179 | case 'info': | ||
180 | this.infoCount += 1; | ||
181 | break; | ||
182 | } | ||
183 | }); | ||
184 | } | ||
185 | |||
186 | get highestDiagnosticLevel(): Diagnostic['severity'] | null { | ||
187 | if (this.errorCount > 0) { | ||
188 | return 'error'; | ||
189 | } | ||
190 | if (this.warningCount > 0) { | ||
191 | return 'warning'; | ||
192 | } | ||
193 | if (this.infoCount > 0) { | ||
194 | return 'info'; | ||
195 | } | ||
196 | return null; | ||
197 | } | ||
198 | |||
156 | /** | 199 | /** |
157 | * @returns `true` if there is history to undo | 200 | * @returns `true` if there is history to undo |
158 | */ | 201 | */ |