Improve YAML handling

Fix atom handling and add syntax highlighting
pull/241/head
Wilfred Hughes 2022-04-03 22:26:33 +07:00
parent 0c1e539373
commit 10a0e2dba9
5 changed files with 69 additions and 8 deletions

@ -133,9 +133,9 @@ c1d8b44875121d81c583dd3a8fb43232 -
sample_files/typing_before.ml sample_files/typing_after.ml
ceba89e4ffc8406454d337638c7d45e6 -
sample_files/yaml_before.yaml sample_files/yaml_after.yaml
1ae5db1355627f3ca607d76c3e6eed9a -
sample_files/zig_before.zig sample_files/zig_after.zig
fb12532adf98607fc20836b4a6ccd6d8 -
sample_files/yaml_before.yaml sample_files/yaml_after.yaml
248e288a193fe8f7b28c11bc7b5a9296 -

@ -1,6 +1,6 @@
---
foo: [bar, foobar]
hello:
- world
- item
- "world"
- 'item'
- other

@ -1,5 +1,5 @@
---
foo: [foobar]
hello:
- world
- "world"
- other

@ -560,9 +560,19 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig {
TreeSitterConfig {
name: "YAML",
language,
atom_nodes: (vec!["string", "template_string"]).into_iter().collect(),
atom_nodes: (vec![
"string_scalar",
"double_quote_scalar",
"single_quote_scalar",
])
.into_iter()
.collect(),
delimiter_tokens: (vec![("{", "}"), ("(", ")"), ("[", "]")]),
highlight_query: ts::Query::new(language, "").unwrap(),
highlight_query: ts::Query::new(
language,
include_str!("../vendor/highlights/yaml.scm"),
)
.unwrap(),
}
}
Zig => {

@ -0,0 +1,51 @@
;; Taken from nvim-treesitter, under Apache license.
;; Upstream URL:https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/yaml/highlights.scm
(boolean_scalar) @boolean
(null_scalar) @constant.builtin
(double_quote_scalar) @string
(single_quote_scalar) @string
(block_scalar) @string
(string_scalar) @string
(escape_sequence) @string.escape
(integer_scalar) @number
(float_scalar) @number
(comment) @comment
(anchor_name) @type
(alias_name) @type
(tag) @type
(yaml_directive) @keyword
(ERROR) @error
(block_mapping_pair
key: (flow_node [(double_quote_scalar) (single_quote_scalar)] @field))
(block_mapping_pair
key: (flow_node (plain_scalar (string_scalar) @field)))
(flow_mapping
(_ key: (flow_node [(double_quote_scalar) (single_quote_scalar)] @field)))
(flow_mapping
(_ key: (flow_node (plain_scalar (string_scalar) @field))))
[
","
"-"
":"
">"
"?"
"|"
] @punctuation.delimiter
[
"["
"]"
"{"
"}"
] @punctuation.bracket
[
"*"
"&"
"---"
"..."
] @punctuation.special