aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/editor/EditorStore.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-11-01 12:05:21 -0400
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-11-05 19:41:33 +0100
commitffe5b08149681f51625bdac43c7ab41ccf5f9cc3 (patch)
treef19137f20c73613ed8d4e63a725e4a1d20a00ec2 /subprojects/frontend/src/editor/EditorStore.ts
parentfeat(frontend): overlay scrollbars for editor (diff)
downloadrefinery-ffe5b08149681f51625bdac43c7ab41ccf5f9cc3.tar.gz
refinery-ffe5b08149681f51625bdac43c7ab41ccf5f9cc3.tar.zst
refinery-ffe5b08149681f51625bdac43c7ab41ccf5f9cc3.zip
feat(frontend): scrollbar annotations
Diffstat (limited to 'subprojects/frontend/src/editor/EditorStore.ts')
-rw-r--r--subprojects/frontend/src/editor/EditorStore.ts53
1 files changed, 30 insertions, 23 deletions
diff --git a/subprojects/frontend/src/editor/EditorStore.ts b/subprojects/frontend/src/editor/EditorStore.ts
index 4ee24779..acad3d09 100644
--- a/subprojects/frontend/src/editor/EditorStore.ts
+++ b/subprojects/frontend/src/editor/EditorStore.ts
@@ -11,6 +11,7 @@ import {
11 type Transaction, 11 type Transaction,
12 type TransactionSpec, 12 type TransactionSpec,
13 type EditorState, 13 type EditorState,
14 RangeSet,
14} from '@codemirror/state'; 15} from '@codemirror/state';
15import { type Command, EditorView } from '@codemirror/view'; 16import { type Command, EditorView } from '@codemirror/view';
16import { makeAutoObservable, observable } from 'mobx'; 17import { makeAutoObservable, observable } from 'mobx';
@@ -20,6 +21,7 @@ import type PWAStore from '../PWAStore';
20import getLogger from '../utils/getLogger'; 21import getLogger from '../utils/getLogger';
21import XtextClient from '../xtext/XtextClient'; 22import XtextClient from '../xtext/XtextClient';
22 23
24import DiagnosticValue from './DiagnosticValue';
23import LintPanelStore from './LintPanelStore'; 25import LintPanelStore from './LintPanelStore';
24import SearchPanelStore from './SearchPanelStore'; 26import SearchPanelStore from './SearchPanelStore';
25import createEditorState from './createEditorState'; 27import createEditorState from './createEditorState';
@@ -46,11 +48,7 @@ export default class EditorStore {
46 48
47 showLineNumbers = false; 49 showLineNumbers = false;
48 50
49 errorCount = 0; 51 diagnostics: RangeSet<DiagnosticValue> = RangeSet.of([]);
50
51 warningCount = 0;
52
53 infoCount = 0;
54 52
55 constructor(initialValue: string, pwaStore: PWAStore) { 53 constructor(initialValue: string, pwaStore: PWAStore) {
56 this.id = nanoid(); 54 this.id = nanoid();
@@ -161,6 +159,9 @@ export default class EditorStore {
161 log.trace('Editor transaction', tr); 159 log.trace('Editor transaction', tr);
162 this.state = tr.state; 160 this.state = tr.state;
163 this.client.onTransaction(tr); 161 this.client.onTransaction(tr);
162 if (tr.docChanged) {
163 this.diagnostics = this.diagnostics.map(tr.changes);
164 }
164 } 165 }
165 166
166 doCommand(command: Command): boolean { 167 doCommand(command: Command): boolean {
@@ -178,25 +179,31 @@ export default class EditorStore {
178 } 179 }
179 180
180 updateDiagnostics(diagnostics: Diagnostic[]): void { 181 updateDiagnostics(diagnostics: Diagnostic[]): void {
182 diagnostics.sort((a, b) => a.from - b.from);
181 this.dispatch(setDiagnostics(this.state, diagnostics)); 183 this.dispatch(setDiagnostics(this.state, diagnostics));
182 this.errorCount = 0; 184 this.diagnostics = RangeSet.of(
183 this.warningCount = 0; 185 diagnostics.map(({ severity, from, to }) =>
184 this.infoCount = 0; 186 DiagnosticValue.VALUES[severity].range(from, to),
185 diagnostics.forEach(({ severity }) => { 187 ),
186 switch (severity) { 188 );
187 case 'error': 189 }
188 this.errorCount += 1; 190
189 break; 191 countDiagnostics(severity: Diagnostic['severity']): number {
190 case 'warning': 192 return this.diagnostics.update({
191 this.warningCount += 1; 193 filter: (_from, _to, value) => value.eq(DiagnosticValue.VALUES[severity]),
192 break; 194 }).size;
193 case 'info': 195 }
194 this.infoCount += 1; 196
195 break; 197 get errorCount(): number {
196 default: 198 return this.countDiagnostics('error');
197 throw new Error('Unknown severity'); 199 }
198 } 200
199 }); 201 get warningCount(): number {
202 return this.countDiagnostics('warning');
203 }
204
205 get infoCount(): number {
206 return this.countDiagnostics('info');
200 } 207 }
201 208
202 nextDiagnostic(): void { 209 nextDiagnostic(): void {