From 9e393247f0fa409e2909904592fbddefbf40fc06 Mon Sep 17 00:00:00 2001 From: "George \"Riye\" Hollister" Date: Sun, 17 Mar 2024 22:54:05 +0000 Subject: [PATCH] Add Support for JSONC (#9906) * Added `jsonc` language with support for comments The `vscode-json-language-server` accepts `jsonc` as a language id. Allowing the use of comments within JSON files. * fix: Update `injdection-rejex` to be unique * fix: use includes to remove redundant queries * ci: Generate language-support docs --- book/src/generated/lang-support.md | 1 + languages.toml | 10 +++++++++- runtime/queries/jsonc/highlights.scm | 2 ++ runtime/queries/jsonc/indents.scm | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/jsonc/highlights.scm create mode 100644 runtime/queries/jsonc/indents.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 2cb1e926ce31..40029657f55f 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -88,6 +88,7 @@ | jsdoc | ✓ | | | | | json | ✓ | | ✓ | `vscode-json-language-server` | | json5 | ✓ | | | | +| jsonc | ✓ | | ✓ | `vscode-json-language-server` | | jsonnet | ✓ | | | `jsonnet-language-server` | | jsx | ✓ | ✓ | ✓ | `typescript-language-server` | | julia | ✓ | ✓ | ✓ | `julia` | diff --git a/languages.toml b/languages.toml index b01da144d52f..4018fbe0e329 100644 --- a/languages.toml +++ b/languages.toml @@ -367,7 +367,6 @@ scope = "source.json" injection-regex = "json" file-types = [ "json", - "jsonc", "arb", "ipynb", "geojson", @@ -396,6 +395,15 @@ indent = { tab-width = 2, unit = " " } name = "json" source = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "73076754005a460947cafe8e03a8cf5fa4fa2938" } +[[language]] +name = "jsonc" +scope = "source.json" +injection-regex = "jsonc" +file-types = ["jsonc"] +grammar = "json" +language-servers = [ "vscode-json-language-server" ] +auto-format = true +indent = { tab-width = 2, unit = " " } [[language]] name = "json5" diff --git a/runtime/queries/jsonc/highlights.scm b/runtime/queries/jsonc/highlights.scm new file mode 100644 index 000000000000..0164321b60d5 --- /dev/null +++ b/runtime/queries/jsonc/highlights.scm @@ -0,0 +1,2 @@ +; inherits: json +(comment) @comment diff --git a/runtime/queries/jsonc/indents.scm b/runtime/queries/jsonc/indents.scm new file mode 100644 index 000000000000..41269219efd8 --- /dev/null +++ b/runtime/queries/jsonc/indents.scm @@ -0,0 +1 @@ +; inherits: json