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