From cc27b2fbea058022f2f3fc3b3f74d91355d7e237 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 25 Nov 2022 15:28:56 +0100 Subject: refactor(frontend): simplify diagnostic tracking --- subprojects/frontend/src/editor/EditorStore.ts | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'subprojects/frontend/src/editor/EditorStore.ts') 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 { type Transaction, type TransactionSpec, type EditorState, - RangeSet, } from '@codemirror/state'; import { type Command, EditorView } from '@codemirror/view'; import { makeAutoObservable, observable } from 'mobx'; @@ -24,10 +23,10 @@ import type PWAStore from '../PWAStore'; import getLogger from '../utils/getLogger'; import XtextClient from '../xtext/XtextClient'; -import DiagnosticValue from './DiagnosticValue'; import LintPanelStore from './LintPanelStore'; import SearchPanelStore from './SearchPanelStore'; import createEditorState from './createEditorState'; +import { countDiagnostics } from './exposeDiagnostics'; import { type IOccurrence, setOccurrences } from './findOccurrences'; import { type IHighlightRange, @@ -51,8 +50,6 @@ export default class EditorStore { showLineNumbers = false; - diagnostics: RangeSet = RangeSet.of([]); - constructor(initialValue: string, pwaStore: PWAStore) { this.id = nanoid(); this.state = createEditorState(initialValue, this); @@ -162,9 +159,6 @@ export default class EditorStore { log.trace('Editor transaction', tr); this.state = tr.state; this.client.onTransaction(tr); - if (tr.docChanged) { - this.diagnostics = this.diagnostics.map(tr.changes); - } } doCommand(command: Command): boolean { @@ -182,31 +176,19 @@ export default class EditorStore { } updateDiagnostics(diagnostics: Diagnostic[]): void { - diagnostics.sort((a, b) => a.from - b.from); this.dispatch(setDiagnostics(this.state, diagnostics)); - this.diagnostics = RangeSet.of( - diagnostics.map(({ severity, from, to }) => - DiagnosticValue.VALUES[severity].range(from, to), - ), - ); - } - - countDiagnostics(severity: Diagnostic['severity']): number { - return this.diagnostics.update({ - filter: (_from, _to, value) => value.eq(DiagnosticValue.VALUES[severity]), - }).size; } get errorCount(): number { - return this.countDiagnostics('error'); + return countDiagnostics(this.state, 'error'); } get warningCount(): number { - return this.countDiagnostics('warning'); + return countDiagnostics(this.state, 'warning'); } get infoCount(): number { - return this.countDiagnostics('info'); + return countDiagnostics(this.state, 'info'); } nextDiagnostic(): void { -- cgit v1.2.3-54-g00ecf