From 5ccb3ff9a1f1aa4fc2bb8e977bf44f8fe2c6893c Mon Sep 17 00:00:00 2001 From: George Hollister Date: Sun, 17 Mar 2024 14:35:40 +0000 Subject: [PATCH 1/4] 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. --- languages.toml | 10 +++++++++- runtime/queries/jsonc/highlights.scm | 22 ++++++++++++++++++++++ runtime/queries/jsonc/indents.scm | 9 +++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/jsonc/highlights.scm create mode 100644 runtime/queries/jsonc/indents.scm diff --git a/languages.toml b/languages.toml index 8fbb98e883d1..186f84f194d3 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 = "json" +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..abbc0d2f713d --- /dev/null +++ b/runtime/queries/jsonc/highlights.scm @@ -0,0 +1,22 @@ +[ + (true) + (false) +] @constant.builtin.boolean +(null) @constant.builtin +(number) @constant.numeric +(pair + key: (_) @keyword) + +(string) @string +(escape_sequence) @constant.character.escape +(ERROR) @error + +"," @punctuation.delimiter +[ + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(comment) @comment diff --git a/runtime/queries/jsonc/indents.scm b/runtime/queries/jsonc/indents.scm new file mode 100644 index 000000000000..f756e609acfe --- /dev/null +++ b/runtime/queries/jsonc/indents.scm @@ -0,0 +1,9 @@ +[ + (object) + (array) +] @indent + +[ + "]" + "}" +] @outdent From 8d3cf78e21fd4892ee7d39a40c97081fd65d12b4 Mon Sep 17 00:00:00 2001 From: George Hollister Date: Sun, 17 Mar 2024 14:39:28 +0000 Subject: [PATCH 2/4] fix: Update `injdection-rejex` to be unique --- languages.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index 186f84f194d3..7fa3c48338c2 100644 --- a/languages.toml +++ b/languages.toml @@ -398,7 +398,7 @@ source = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "73076 [[language]] name = "jsonc" scope = "source.json" -injection-regex = "json" +injection-regex = "jsonc" file-types = ["jsonc"] grammar = "json" language-servers = [ "vscode-json-language-server" ] From 35bda4f0a09fd07decabec10ad65a8198be09c33 Mon Sep 17 00:00:00 2001 From: George Hollister Date: Sun, 17 Mar 2024 17:09:52 +0000 Subject: [PATCH 3/4] fix: use includes to remove redundant queries --- runtime/queries/jsonc/highlights.scm | 22 +--------------------- runtime/queries/jsonc/indents.scm | 10 +--------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/runtime/queries/jsonc/highlights.scm b/runtime/queries/jsonc/highlights.scm index abbc0d2f713d..0164321b60d5 100644 --- a/runtime/queries/jsonc/highlights.scm +++ b/runtime/queries/jsonc/highlights.scm @@ -1,22 +1,2 @@ -[ - (true) - (false) -] @constant.builtin.boolean -(null) @constant.builtin -(number) @constant.numeric -(pair - key: (_) @keyword) - -(string) @string -(escape_sequence) @constant.character.escape -(ERROR) @error - -"," @punctuation.delimiter -[ - "[" - "]" - "{" - "}" -] @punctuation.bracket - +; inherits: json (comment) @comment diff --git a/runtime/queries/jsonc/indents.scm b/runtime/queries/jsonc/indents.scm index f756e609acfe..41269219efd8 100644 --- a/runtime/queries/jsonc/indents.scm +++ b/runtime/queries/jsonc/indents.scm @@ -1,9 +1 @@ -[ - (object) - (array) -] @indent - -[ - "]" - "}" -] @outdent +; inherits: json From b21f8982229e290248f9b3c1534b14f73eb6a89f Mon Sep 17 00:00:00 2001 From: George Hollister Date: Sun, 17 Mar 2024 19:44:51 +0000 Subject: [PATCH 4/4] ci: Generate language-support docs --- book/src/generated/lang-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 7792bf594181..9166fb956792 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -87,6 +87,7 @@ | jsdoc | ✓ | | | | | json | ✓ | | ✓ | `vscode-json-language-server` | | json5 | ✓ | | | | +| jsonc | ✓ | | ✓ | `vscode-json-language-server` | | jsonnet | ✓ | | | `jsonnet-language-server` | | jsx | ✓ | ✓ | ✓ | `typescript-language-server` | | julia | ✓ | ✓ | ✓ | `julia` |