Add separate JSONC language (#12655)
Resolves https://github.com/zed-industries/extensions/issues/860 and https://github.com/zed-industries/zed/issues/10921, also https://github.com/biomejs/biome-zed/issues/11. ### Problem: When opening .json files, zed allows comments by default in the JSON language, which can cause some problems. For example, language-servers also get "json" as the language, which may show errors for those comments. <img width="935" alt="image" src="https://github.com/zed-industries/zed/assets/10381895/fed3d83d-abc0-44b5-9982-eb249bb04c3b"> ### Solution: This PR adds a JSONC language. <img width="816" alt="image" src="https://github.com/zed-industries/zed/assets/10381895/8b40e671-d4f0-4e8d-80cb-82ee7c0ec490"> This allows for more specific configuration for language servers. Also any json file can be set explicitly to be JSONC using the file_types setting: ```jsonc { "file_types": { // set all .json files to be seen as JSONC "JSONC": ["*.json"] } } ``` Release Notes: - N/A
This commit is contained in:
parent
e71b642f44
commit
fb3ef0d140
13 changed files with 98 additions and 3 deletions
3
crates/languages/src/jsonc/brackets.scm
Normal file
3
crates/languages/src/jsonc/brackets.scm
Normal file
|
@ -0,0 +1,3 @@
|
|||
("[" @open "]" @close)
|
||||
("{" @open "}" @close)
|
||||
("\"" @open "\"" @close)
|
12
crates/languages/src/jsonc/config.toml
Normal file
12
crates/languages/src/jsonc/config.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
name = "JSONC"
|
||||
grammar = "jsonc"
|
||||
path_suffixes = ["jsonc"]
|
||||
line_comments = ["// "]
|
||||
autoclose_before = ",]}"
|
||||
brackets = [
|
||||
{ start = "{", end = "}", close = true, newline = true },
|
||||
{ start = "[", end = "]", close = true, newline = true },
|
||||
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
|
||||
]
|
||||
tab_size = 2
|
||||
prettier_parser_name = "jsonc"
|
14
crates/languages/src/jsonc/embedding.scm
Normal file
14
crates/languages/src/jsonc/embedding.scm
Normal file
|
@ -0,0 +1,14 @@
|
|||
; Only produce one embedding for the entire file.
|
||||
(document) @item
|
||||
|
||||
; Collapse arrays, except for the first object.
|
||||
(array
|
||||
"[" @keep
|
||||
.
|
||||
(object)? @keep
|
||||
"]" @keep) @collapse
|
||||
|
||||
; Collapse string values (but not keys).
|
||||
(pair value: (string
|
||||
"\"" @keep
|
||||
"\"" @keep) @collapse)
|
21
crates/languages/src/jsonc/highlights.scm
Normal file
21
crates/languages/src/jsonc/highlights.scm
Normal file
|
@ -0,0 +1,21 @@
|
|||
(comment) @comment
|
||||
|
||||
(string) @string
|
||||
|
||||
(pair
|
||||
key: (string) @property.json_key)
|
||||
|
||||
(number) @number
|
||||
|
||||
[
|
||||
(true)
|
||||
(false)
|
||||
(null)
|
||||
] @constant
|
||||
|
||||
[
|
||||
"{"
|
||||
"}"
|
||||
"["
|
||||
"]"
|
||||
] @punctuation.bracket
|
2
crates/languages/src/jsonc/indents.scm
Normal file
2
crates/languages/src/jsonc/indents.scm
Normal file
|
@ -0,0 +1,2 @@
|
|||
(array "]" @end) @indent
|
||||
(object "}" @end) @indent
|
2
crates/languages/src/jsonc/outline.scm
Normal file
2
crates/languages/src/jsonc/outline.scm
Normal file
|
@ -0,0 +1,2 @@
|
|||
(pair
|
||||
key: (string (string_content) @name)) @item
|
1
crates/languages/src/jsonc/overrides.scm
Normal file
1
crates/languages/src/jsonc/overrides.scm
Normal file
|
@ -0,0 +1 @@
|
|||
(string) @string
|
4
crates/languages/src/jsonc/redactions.scm
Normal file
4
crates/languages/src/jsonc/redactions.scm
Normal file
|
@ -0,0 +1,4 @@
|
|||
(pair value: (number) @redact)
|
||||
(pair value: (string) @redact)
|
||||
(array (number) @redact)
|
||||
(array (string) @redact)
|
Loading…
Add table
Add a link
Reference in a new issue