mirror of
https://github.com/jimeh/.emacs.d.git
synced 2026-02-19 13:46:41 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user