Skip to content

Commit

Permalink
try: to check in web-app
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Sep 8, 2023
1 parent 01ccd15 commit d225b53
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/other/codemirror/CodeMirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class CodeMirror extends React.Component<CodeMirrorProps, CodeMirrorState> {
const { isLoaded, isEditing } = this.state;
const { updateContent, updateOnFirstLoad = true } = this.props;
// kludge for the way state management is handled in web-app
// TODO: RESTORE whatever was removed here!!!!
if (!isLoaded && !updateOnFirstLoad) {
this.setState({ isLoaded: true });
return;
Expand All @@ -86,11 +87,12 @@ class CodeMirror extends React.Component<CodeMirrorProps, CodeMirrorState> {
}

updateChecks(viewUpdate: ViewUpdate) {
console.log("updateChecks viewUpdate", viewUpdate);
// console.log("updateChecks viewUpdate", viewUpdate);
const { checks } = this.props;
if (checks && checks.keys.length > 0) {
viewUpdate.view.dispatch({
annotations: [ChecksAnnotation.of({ checks })],
sequential: true,
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/other/codemirror/utils/exaxyz_linter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Diagnostic } from "@codemirror/lint";
import { Annotation, StateField } from "@codemirror/state";
import { Annotation, StateField, Transaction } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
// eslint-disable-next-line import/no-extraneous-dependencies
import { ConsistencyChecks } from "@exabyte-io/code.js/src/types";
Expand All @@ -8,23 +8,23 @@ import _ from "underscore";
export const ChecksAnnotation = Annotation.define<{ checks: ConsistencyChecks }>();

export const checksStateField = StateField.define({
// @ts-ignore
create() {
return [];
create(): ConsistencyChecks {
return { keys: [], messages: [] };
},
update: _.debounce((value: ConsistencyChecks, tr) => {
update: (value: ConsistencyChecks, tr: Transaction) => {
if (tr.annotation(ChecksAnnotation)) {
// @ts-ignore
return tr.annotation(ChecksAnnotation).checks;
}
return value;
}, 300), // debounce for 300ms
},
});
const exaxyzLinter = (view: EditorView): Diagnostic[] => {
// TODO: REMOVE type casting
const checks: ConsistencyChecks | undefined = view.state.field(checksStateField) as
| ConsistencyChecks
| undefined;
console.log(view.state.update());

if (!checks) return [];
if (Object.keys(checks).length === 0) return [];
Expand Down

0 comments on commit d225b53

Please sign in to comment.