jsonnext / codemirror-json-schema

A JSONSchema enabled mode for codemirror 6, for json4 and json5, inspired by monaco-json
https://codemirror-json-schema.netlify.app
MIT License
57 stars 9 forks source link

Console error (json format error) #79

Closed kezhongfa closed 6 months ago

kezhongfa commented 7 months ago

Phenomenon: official website demo must appear. image Reproduction step: add "," to any value. Desired: error message syntax highlighting. image

acao commented 7 months ago

are you using the "simple" or "custom" approach?

kezhongfa commented 7 months ago

are you using the "simple" or "custom" approach?

simple. I'm just giving an example. The console shouldn't report errors, it has to show the user the error message and know how to change it.

nowaylifer commented 6 months ago

Encountered it too. Filtering out diagnostics with from and to properties that equals undefined seems to solve the problem.

import { jsonParseLinter } from '@codemirror/lang-json';
import { jsonSchemaLinter } from 'codemirror-json-schema';

const lintJson = jsonParseLinter();
const lintJsonSchema = jsonSchemaLinter();

export function customJsonLinter() {
  return (view: EditorView) => {
    const parseErrors = lintJson(view);
    const schemaErrors = lintJsonSchema(view).filter(
      (diagnostic) => diagnostic.from !== undefined && diagnostic.to !== undefined
    );

    return [...schemaErrors, ...parseErrors];
  };
}
acao commented 6 months ago

good catch, this is a recently introduced regression (from fixing required property validation) that we don't test for yet!

acao commented 6 months ago

after closer debugging, it's related to the introduction of new error types in our dependency which handles validation. I have a branch that should fix this!