From ebbdab36fb2a3d635d591cc3179b8f4ed9a476d0 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 24 Nov 2022 02:30:26 +0000 Subject: [PATCH] feat(language/yaml): enable tree-sitter syntax highlighting Provide full tree-sitter highlight queries for YAML mode, and enable tree-sitter-mode within yaml-mode buffers. --- modules/languages/siren-yaml.el | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/modules/languages/siren-yaml.el b/modules/languages/siren-yaml.el index 800e6d3..fa88c78 100644 --- a/modules/languages/siren-yaml.el +++ b/modules/languages/siren-yaml.el @@ -8,6 +8,7 @@ (require 'siren-lsp) (require 'siren-prog-mode) +(require 'siren-tree-sitter) (use-package yaml-mode :mode "\\.yml\\'" "\\.yaml\\'" @@ -19,10 +20,47 @@ (yaml-mode . siren-yaml-mode-setup) :preface + ;; Manually set full tree-sitter highlight queries for yaml-mode. This is a + ;; temporary workaround until this PR is merged: + ;; https://github.com/emacs-tree-sitter/tree-sitter-langs/pull/134 + (defun siren-yaml-mode-tree-sitter-setup () + (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 ])) + (defun siren-yaml-mode-setup () (run-hooks 'prog-mode-hook) (setq-local tab-width 2) + (siren-yaml-mode-tree-sitter-setup) + (tree-sitter-mode t) (subword-mode t))) (use-package lsp-yaml