aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/editor/EditorStore.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-11-25 15:28:56 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-12-09 00:07:38 +0100
commitcc27b2fbea058022f2f3fc3b3f74d91355d7e237 (patch)
tree7b81505b181c821f66aa629f7702b975bd9eb2b3 /subprojects/frontend/src/editor/EditorStore.ts
parentchore(web): fix lint error (diff)
downloadrefinery-cc27b2fbea058022f2f3fc3b3f74d91355d7e237.tar.gz
refinery-cc27b2fbea058022f2f3fc3b3f74d91355d7e237.tar.zst
refinery-cc27b2fbea058022f2f3fc3b3f74d91355d7e237.zip
refactor(frontend): simplify diagnostic tracking
Diffstat (limited to 'subprojects/frontend/src/editor/EditorStore.ts')
-rw-r--r--subprojects/frontend/src/editor/EditorStore.ts26
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';
19import { type Command, EditorView } from '@codemirror/view'; 18import { type Command, EditorView } from '@codemirror/view';
20import { makeAutoObservable, observable } from 'mobx'; 19import { makeAutoObservable, observable } from 'mobx';
@@ -24,10 +23,10 @@ import type PWAStore from '../PWAStore';
24import getLogger from '../utils/getLogger'; 23import getLogger from '../utils/getLogger';
25import XtextClient from '../xtext/XtextClient'; 24import XtextClient from '../xtext/XtextClient';
26 25
27import DiagnosticValue from './DiagnosticValue';
28import LintPanelStore from './LintPanelStore'; 26import LintPanelStore from './LintPanelStore';
29import SearchPanelStore from './SearchPanelStore'; 27import SearchPanelStore from './SearchPanelStore';
30import createEditorState from './createEditorState'; 28import createEditorState from './createEditorState';
29import { countDiagnostics } from './exposeDiagnostics';
31import { type IOccurrence, setOccurrences } from './findOccurrences'; 30import { type IOccurrence, setOccurrences } from './findOccurrences';
32import { 31import {
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 {