@bhsd/lezer-json
v2.3.0
Published
Lezer-based JSON/JSONC grammar
Readme
@bhsd/lezer-json
This is a fork of @lezer/json and @codemirror/lang-json that adds a dialect for JSONC to provide support for comments and trailing commas.
Installation
You can install the package via npm and import it as a module:
npm install @bhsd/lezer-jsonLanguage Support
You can directly import the language support that provides both the language and the basic completion source for JSON or JSONC.
import {json} from '@bhsd/lezer-json';
import type {LanguageSupport} from '@codemirror/language';
const jsonLanguageSupport: LanguageSupport = json(),
jsoncLanguageSupport: LanguageSupport = json('jsonc');Language
You can also import the LR language for JSON or JSONC alone.
import {jsonLanguage, jsoncLanguage} from '@bhsd/lezer-json';Completion Source
If you are importing the language alone, you can choose to import the completion source which provides basic completion for both JSON and JSONC.
import {jsonCompletionSource, jsonLanguage, jsoncLanguage} from '@bhsd/lezer-json';
import type {Extension} from '@codemirror/state';
const jsonCompletion: Extension = jsonLanguage.data.of({autocomplete: jsonCompletionSource}),
jsoncCompletion: Extension = jsoncLanguage.data.of({autocomplete: jsonCompletionSource});Lint Source
This package also provides lint sources for JSON or JSONC syntax checking. This is not included in the language support by default.
import {linter} from '@codemirror/lint';
import {jsonLinter, jsoncLinter} from '@bhsd/lezer-json';
import type {Extension} from '@codemirror/state';
const jsonLintExtension: Extension = linter(jsonLinter),
jsoncLintExtension: Extension = linter(jsoncLinter);