diff options
Diffstat (limited to 'subprojects/frontend/src/editor/EditorStore.ts')
-rw-r--r-- | subprojects/frontend/src/editor/EditorStore.ts | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/subprojects/frontend/src/editor/EditorStore.ts b/subprojects/frontend/src/editor/EditorStore.ts index d966690c..1f301c31 100644 --- a/subprojects/frontend/src/editor/EditorStore.ts +++ b/subprojects/frontend/src/editor/EditorStore.ts | |||
@@ -14,7 +14,6 @@ import { | |||
14 | type Transaction, | 14 | type Transaction, |
15 | type TransactionSpec, | 15 | type TransactionSpec, |
16 | type EditorState, | 16 | type EditorState, |
17 | RangeSet, | ||
18 | } from '@codemirror/state'; | 17 | } from '@codemirror/state'; |
19 | import { type Command, EditorView } from '@codemirror/view'; | 18 | import { type Command, EditorView } from '@codemirror/view'; |
20 | import { makeAutoObservable, observable } from 'mobx'; | 19 | import { makeAutoObservable, observable } from 'mobx'; |
@@ -24,10 +23,10 @@ import type PWAStore from '../PWAStore'; | |||
24 | import getLogger from '../utils/getLogger'; | 23 | import getLogger from '../utils/getLogger'; |
25 | import XtextClient from '../xtext/XtextClient'; | 24 | import XtextClient from '../xtext/XtextClient'; |
26 | 25 | ||
27 | import DiagnosticValue from './DiagnosticValue'; | ||
28 | import LintPanelStore from './LintPanelStore'; | 26 | import LintPanelStore from './LintPanelStore'; |
29 | import SearchPanelStore from './SearchPanelStore'; | 27 | import SearchPanelStore from './SearchPanelStore'; |
30 | import createEditorState from './createEditorState'; | 28 | import createEditorState from './createEditorState'; |
29 | import { countDiagnostics } from './exposeDiagnostics'; | ||
31 | import { type IOccurrence, setOccurrences } from './findOccurrences'; | 30 | import { type IOccurrence, setOccurrences } from './findOccurrences'; |
32 | import { | 31 | import { |
33 | type IHighlightRange, | 32 | type IHighlightRange, |
@@ -51,8 +50,6 @@ export default class EditorStore { | |||
51 | 50 | ||
52 | showLineNumbers = false; | 51 | showLineNumbers = false; |
53 | 52 | ||
54 | diagnostics: RangeSet<DiagnosticValue> = RangeSet.of([]); | ||
55 | |||
56 | constructor(initialValue: string, pwaStore: PWAStore) { | 53 | constructor(initialValue: string, pwaStore: PWAStore) { |
57 | this.id = nanoid(); | 54 | this.id = nanoid(); |
58 | this.state = createEditorState(initialValue, this); | 55 | this.state = createEditorState(initialValue, this); |
@@ -162,9 +159,6 @@ export default class EditorStore { | |||
162 | log.trace('Editor transaction', tr); | 159 | log.trace('Editor transaction', tr); |
163 | this.state = tr.state; | 160 | this.state = tr.state; |
164 | this.client.onTransaction(tr); | 161 | this.client.onTransaction(tr); |
165 | if (tr.docChanged) { | ||
166 | this.diagnostics = this.diagnostics.map(tr.changes); | ||
167 | } | ||
168 | } | 162 | } |
169 | 163 | ||
170 | doCommand(command: Command): boolean { | 164 | doCommand(command: Command): boolean { |
@@ -182,31 +176,19 @@ export default class EditorStore { | |||
182 | } | 176 | } |
183 | 177 | ||
184 | updateDiagnostics(diagnostics: Diagnostic[]): void { | 178 | updateDiagnostics(diagnostics: Diagnostic[]): void { |
185 | diagnostics.sort((a, b) => a.from - b.from); | ||
186 | this.dispatch(setDiagnostics(this.state, diagnostics)); | 179 | this.dispatch(setDiagnostics(this.state, diagnostics)); |
187 | this.diagnostics = RangeSet.of( | ||
188 | diagnostics.map(({ severity, from, to }) => | ||
189 | DiagnosticValue.VALUES[severity].range(from, to), | ||
190 | ), | ||
191 | ); | ||
192 | } | ||
193 | |||
194 | countDiagnostics(severity: Diagnostic['severity']): number { | ||
195 | return this.diagnostics.update({ | ||
196 | filter: (_from, _to, value) => value.eq(DiagnosticValue.VALUES[severity]), | ||
197 | }).size; | ||
198 | } | 180 | } |
199 | 181 | ||
200 | get errorCount(): number { | 182 | get errorCount(): number { |
201 | return this.countDiagnostics('error'); | 183 | return countDiagnostics(this.state, 'error'); |
202 | } | 184 | } |
203 | 185 | ||
204 | get warningCount(): number { | 186 | get warningCount(): number { |
205 | return this.countDiagnostics('warning'); | 187 | return countDiagnostics(this.state, 'warning'); |
206 | } | 188 | } |
207 | 189 | ||
208 | get infoCount(): number { | 190 | get infoCount(): number { |
209 | return this.countDiagnostics('info'); | 191 | return countDiagnostics(this.state, 'info'); |
210 | } | 192 | } |
211 | 193 | ||
212 | nextDiagnostic(): void { | 194 | nextDiagnostic(): void { |