From 1dfd9d28a059cf28a2ef595756b68f2a16bc0fae Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 13 May 2024 01:21:18 +0100 Subject: [PATCH] fix(language/yaml): define custom tree-sitter queries The upstream queries have been modified causing a dramatic change to the visual coloring of syntax highlighting of YAML files when using tree-sitter-mode. Hence I'm here setting custom highlight queries that work my preferred way. --- modules/languages/siren-yaml.el | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/languages/siren-yaml.el b/modules/languages/siren-yaml.el index 366763d..8e80d5b 100644 --- a/modules/languages/siren-yaml.el +++ b/modules/languages/siren-yaml.el @@ -47,7 +47,41 @@ or *.yaml file in a .github/workflows/ directory." :preface (defun siren-yaml-mode-setup () (run-hooks 'prog-mode-hook) - (setq-local tab-width 2)) + (setq-local tab-width 2) + + ;; Manually set custom queries for tree-sitter mode, as I don't like the + ;; default queries now treating all keys as properties rather than + ;; variables, giving them the wrong syntax highlighting color. + (setq-local tree-sitter-hl-default-patterns + [;; keys + (block_mapping_pair + key: (flow_node [(double_quote_scalar) (single_quote_scalar)] @variable)) + (block_mapping_pair + key: (flow_node (plain_scalar (string_scalar) @variable))) + + ;; keys within inline {} blocks + (flow_mapping + (_ key: (flow_node [(double_quote_scalar) (single_quote_scalar)] @variable))) + (flow_mapping + (_ key: (flow_node (plain_scalar (string_scalar) @variable)))) + + ["[" "]" "{" "}"] @punctuation.bracket + ["," "-" ":" "?" ">" "|"] @punctuation.delimiter + ["*" "&" "---" "..."] @punctuation.special + + [(null_scalar) (boolean_scalar)] @constant.builtin + [(integer_scalar) (float_scalar)] @number + [(double_quote_scalar) (single_quote_scalar) (block_scalar)] @string + (escape_sequence) @escape + + (comment) @comment + [(anchor_name) (alias_name)] @function + (yaml_directive) @type + + (tag) @type + (tag_handle) @type + (tag_prefix) @string + (tag_directive) @property ])) :config (siren-flycheck-setup-yaml-actionlint))