mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
Add syntax highlighting/auto-indent/outlines for JSON files
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
4b0300daea
commit
bf1153cedd
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -5326,6 +5326,16 @@ dependencies = [
|
||||
"tree-sitter",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tree-sitter-json"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90b04c4e1a92139535eb9fca4ec8fa9666cc96b618005d3ae35f3c957fa92f92"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"tree-sitter",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tree-sitter-markdown"
|
||||
version = "0.0.1"
|
||||
@ -5935,6 +5945,7 @@ dependencies = [
|
||||
"toml",
|
||||
"tree-sitter",
|
||||
"tree-sitter-c",
|
||||
"tree-sitter-json",
|
||||
"tree-sitter-markdown",
|
||||
"tree-sitter-rust",
|
||||
"unindent",
|
||||
|
@ -92,6 +92,7 @@ tiny_http = "0.8"
|
||||
toml = "0.5"
|
||||
tree-sitter = "0.20.4"
|
||||
tree-sitter-c = "0.20.1"
|
||||
tree-sitter-json = "0.19.0"
|
||||
tree-sitter-rust = "0.20.1"
|
||||
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }
|
||||
url = "2.2"
|
||||
|
3
crates/zed/languages/c/brackets.scm
Normal file
3
crates/zed/languages/c/brackets.scm
Normal file
@ -0,0 +1,3 @@
|
||||
("[" @open "]" @close)
|
||||
("{" @open "}" @close)
|
||||
("\"" @open "\"" @close)
|
3
crates/zed/languages/json/brackets.scm
Normal file
3
crates/zed/languages/json/brackets.scm
Normal file
@ -0,0 +1,3 @@
|
||||
("[" @open "]" @close)
|
||||
("{" @open "}" @close)
|
||||
("\"" @open "\"" @close)
|
7
crates/zed/languages/json/config.toml
Normal file
7
crates/zed/languages/json/config.toml
Normal file
@ -0,0 +1,7 @@
|
||||
name = "JSON"
|
||||
path_suffixes = ["json"]
|
||||
brackets = [
|
||||
{ start = "{", end = "}", close = true, newline = true },
|
||||
{ start = "[", end = "]", close = true, newline = true },
|
||||
{ start = "\"", end = "\"", close = true, newline = false },
|
||||
]
|
12
crates/zed/languages/json/highlights.scm
Normal file
12
crates/zed/languages/json/highlights.scm
Normal file
@ -0,0 +1,12 @@
|
||||
(string) @string
|
||||
|
||||
(pair
|
||||
key: (string) @property)
|
||||
|
||||
(number) @number
|
||||
|
||||
[
|
||||
(true)
|
||||
(false)
|
||||
(null)
|
||||
] @constant
|
2
crates/zed/languages/json/indents.scm
Normal file
2
crates/zed/languages/json/indents.scm
Normal file
@ -0,0 +1,2 @@
|
||||
(array "]" @end) @indent
|
||||
(object "}" @end) @indent
|
2
crates/zed/languages/json/outline.scm
Normal file
2
crates/zed/languages/json/outline.scm
Normal file
@ -0,0 +1,2 @@
|
||||
(pair
|
||||
key: (string (string_content) @name)) @item
|
@ -429,6 +429,7 @@ pub fn build_language_registry() -> LanguageRegistry {
|
||||
.join(".zed"),
|
||||
);
|
||||
languages.add(Arc::new(c()));
|
||||
languages.add(Arc::new(json()));
|
||||
languages.add(Arc::new(rust()));
|
||||
languages.add(Arc::new(markdown()));
|
||||
languages
|
||||
@ -455,6 +456,8 @@ fn c() -> Language {
|
||||
Language::new(config, Some(grammar))
|
||||
.with_highlights_query(load_query("c/highlights.scm").as_ref())
|
||||
.unwrap()
|
||||
.with_brackets_query(load_query("c/brackets.scm").as_ref())
|
||||
.unwrap()
|
||||
.with_indents_query(load_query("c/indents.scm").as_ref())
|
||||
.unwrap()
|
||||
.with_outline_query(load_query("c/outline.scm").as_ref())
|
||||
@ -462,6 +465,20 @@ fn c() -> Language {
|
||||
.with_lsp_ext(CLsp)
|
||||
}
|
||||
|
||||
fn json() -> Language {
|
||||
let grammar = tree_sitter_json::language();
|
||||
let config = toml::from_slice(&LanguageDir::get("json/config.toml").unwrap().data).unwrap();
|
||||
Language::new(config, Some(grammar))
|
||||
.with_highlights_query(load_query("json/highlights.scm").as_ref())
|
||||
.unwrap()
|
||||
.with_brackets_query(load_query("json/brackets.scm").as_ref())
|
||||
.unwrap()
|
||||
.with_indents_query(load_query("json/indents.scm").as_ref())
|
||||
.unwrap()
|
||||
.with_outline_query(load_query("json/outline.scm").as_ref())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn markdown() -> Language {
|
||||
let grammar = tree_sitter_markdown::language();
|
||||
let config = toml::from_slice(&LanguageDir::get("markdown/config.toml").unwrap().data).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user