From 33c8999722cc8fb62f992aa043cfe5ae1c88901f Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Fri, 10 May 2024 23:45:26 -0400 Subject: [PATCH] Support more than 2 captured treesit nodes --- emacs/.emacs.d/config/init-terraform.el | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/emacs/.emacs.d/config/init-terraform.el b/emacs/.emacs.d/config/init-terraform.el index d8c88ed..df443fe 100644 --- a/emacs/.emacs.d/config/init-terraform.el +++ b/emacs/.emacs.d/config/init-terraform.el @@ -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)))