Replies: 1 comment 2 replies
-
There is currently no API to get a node's field name under its parent node. As a workaround, you can use this implementation (it's a bit convoluted, and not as efficient as a Rust implementation could be): (defun tsc-node-field (node)
(when-let* ((parent (tsc-get-parent node))
(cursor (tsc-make-cursor parent))
(_ (tsc-goto-first-child cursor))
(child (tsc-current-node cursor)))
(while (and child (not (tsc-node-eq child node)))
(setq child (if (tsc-goto-next-sibling cursor)
(tsc-current-node cursor)
nil)))
(tsc-current-field cursor))) What is your specific use case, though? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was wondering if there was a way to get the field name of a node. I am not sure if I using the correct terminology, but I was wondering if I can give the
type_identifier
node and get something like:type
or"type"
out of it? I am aware oftsc-get-child-by-field
, but I wanted to lookup the field name if any for a specific node. I was not able to find anything in the elisp files or follow this function.Something with the signature
Node -> Optional<Field>
Beta Was this translation helpful? Give feedback.
All reactions