Skip to content

Commit

Permalink
Show field names in tree-sitter-debug-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrick committed May 11, 2024
1 parent e67aae9 commit f3bfef1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lisp/tree-sitter-debug.el
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ This only takes effect if `tree-sitter-debug-jump-buttons' is non-nil."
(push-mark (byte-to-position (cdr byte-range))
tree-sitter-debug-highlight-jump-region))

(defun tree-sitter-debug--display-node (named-p type start-byte end-byte depth)
(defun tree-sitter-debug--display-node (named-p type start-byte end-byte depth field)
"Display NODE that appears at the given DEPTH in the syntax tree."
(when named-p
(insert (make-string (* 2 depth) ?\ ))
(let ((node-text (format "%s:" type)))
(let* ((field-text (if field
(format " (%s)" field)
""))
(node-text (format "%s%s:" type field-text)))
(if tree-sitter-debug-jump-buttons
(insert-button node-text
'action 'tree-sitter-debug--button-node-lookup
Expand All @@ -82,19 +85,19 @@ This only takes effect if `tree-sitter-debug-jump-buttons' is non-nil."
(pcase tree-sitter-debug-traversal-method
(:mapc (tsc-traverse-mapc
(lambda (props)
(pcase-let ((`[,named-p ,type ,start-byte ,end-byte ,depth] props))
(pcase-let ((`[,named-p ,type ,start-byte ,end-byte ,depth ,field] props))
(tree-sitter-debug--display-node
named-p type start-byte end-byte depth)))
named-p type start-byte end-byte depth field)))
tree
[:named-p :type :start-byte :end-byte :depth]))
[:named-p :type :start-byte :end-byte :depth :field]))
(:iter (iter-do (props (tsc-traverse-iter
tree [:named-p :type :start-byte :end-byte :depth]))
(pcase-let ((`[,named-p ,type ,start-byte ,end-byte ,depth] props))
tree [:named-p :type :start-byte :end-byte :depth :field]))
(pcase-let ((`[,named-p ,type ,start-byte ,end-byte ,depth ,field] props))
(tree-sitter-debug--display-node
named-p type start-byte end-byte depth))))
(:do (tsc-traverse-do ([named-p type start-byte end-byte depth] tree)
named-p type start-byte end-byte depth field))))
(:do (tsc-traverse-do ([named-p type start-byte end-byte depth field] tree)
(tree-sitter-debug--display-node
named-p type start-byte end-byte depth))))))))
named-p type start-byte end-byte depth field))))))))

(defun tree-sitter-debug--setup ()
"Set up syntax tree debugging in the current buffer."
Expand Down

0 comments on commit f3bfef1

Please sign in to comment.