Support more than 2 captured treesit nodes

This commit is contained in:
Jeremy Dormitzer 2024-05-10 23:45:26 -04:00
parent 9f4e0f88ad
commit 33c8999722

View File

@ -16,12 +16,11 @@
(block (treesit-node-top-level current-node "block")) (block (treesit-node-top-level current-node "block"))
(capture (when block (capture (when block
(treesit-query-capture block (treesit-query-capture block
'((block (identifier) @id (:match "^\\(data\\|resource\\)$" @id) '((block (identifier) @type (:match "^\\(data\\|resource\\)$" @type)
(string_lit (_) (template_literal) @name (_)))))))) (string_lit (_) (template_literal) @name (_)))))))
(->> (-take 2 capture) (capture (let ((-compare-fn (lambda (a b) (eq (car a) (car b)))))
(-map (lambda (r) (-distinct capture))))
(let ((key (if (eq (car r) 'id) 'type (car r)))) (-map (lambda (r) (cons (car r) (treesit-node-text (cdr r) t))) capture)))
(cons key (treesit-node-text (cdr r) t))))))))
(defun terraform-block-metadata-at-point () (defun terraform-block-metadata-at-point ()
(terraform-block-metadata-at-pos (point))) (terraform-block-metadata-at-pos (point)))