Hooked up jsonc language mode for Codemirror

This commit is contained in:
Gregory Schier
2026-03-05 06:50:44 -08:00
parent 88f5f0e045
commit 2247d8b158
5 changed files with 22 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { jsonLanguage } from '@codemirror/lang-json';
import { jsoncLanguage } from '@shopify/lang-jsonc';
import { linter } from '@codemirror/lint';
import type { EditorView } from '@codemirror/view';
import type { GrpcRequest } from '@yaakapp-internal/models';
@@ -115,7 +115,7 @@ export function GrpcEditor({
delay: 200,
needsRefresh: handleRefresh,
}),
jsonLanguage.data.of({
jsoncLanguage.data.of({
autocomplete: jsonCompletion(),
}),
stateExtensions({}),

View File

@@ -8,7 +8,7 @@ import { history, historyKeymap } from '@codemirror/commands';
import { go } from '@codemirror/lang-go';
import { java } from '@codemirror/lang-java';
import { javascript } from '@codemirror/lang-javascript';
import { json } from '@codemirror/lang-json';
import { jsonc, jsoncLanguage } from '@shopify/lang-jsonc';
import { markdown } from '@codemirror/lang-markdown';
import { php } from '@codemirror/lang-php';
import { python } from '@codemirror/lang-python';
@@ -107,7 +107,7 @@ const syntaxExtensions: Record<
null | (() => LanguageSupport)
> = {
graphql: null,
json: json,
json: jsonc,
javascript: javascript,
// HTML as XML because HTML is oddly slow
html: xml,
@@ -194,6 +194,11 @@ export function getLanguageExtension({
if (language === 'json') {
extraExtensions.push(linter(jsonParseLinter()));
extraExtensions.push(
jsoncLanguage.data.of({
commentTokens: { line: '//', block: { open: '/*', close: '*/' } },
}),
);
if (!hideGutter) {
extraExtensions.push(lintGutter());
}

View File

@@ -11,7 +11,7 @@ export function jsonParseLinter() {
// We need lint to not break on stuff like {"foo:" ${[ ... ]}} so we'll replace all template
// syntax with repeating `1` characters, so it's valid JSON and the position is still correct.
const escapedDoc = doc.replace(TEMPLATE_SYNTAX_REGEX, (m) => '1'.repeat(m.length));
jsonLintParse(escapedDoc);
jsonLintParse(escapedDoc, { mode: 'cjson' });
// biome-ignore lint/suspicious/noExplicitAny: none
} catch (err: any) {
if (!('location' in err)) {