do (setq node (treesit-node-parent node))
finally return (string-join name-list "."))))
-(defun js--treesit-imenu-top-level-p (node)
- "Return t if NODE is top-level, nil otherwise.
-Being top-level means there is no parent of NODE that has the
-same type."
- (when node
- (catch 'term
- (let ((type (treesit-node-type node)))
- (while (setq node (treesit-node-parent node))
- (when (equal (treesit-node-type node) type)
- (throw 'term nil))))
- t)))
-
;; Keep this private since we might later change it or generalize it.
(defvar js--treesit-imenu-type-alist
'((variable . "V")
((null ts-node)
subtrees)
((and (eq type 'variable)
- (not (js--treesit-imenu-top-level-p ts-node)))
+ (not (treesit-node-top-level-p ts-node)))
nil)
(subtrees
(let ((parent-label (js--treesit-imenu-label type name))
(treesit-buffer-root-node parser-or-lang))))
(treesit-node-descendant-for-range root beg (or end beg) named)))
+(defun treesit-node-top-level-p (node)
+ "Return non-nil if NODE is top-level, nil otherwise.
+Being top-level means there is no parent of NODE that has the
+same type."
+ (when node
+ (catch 'term
+ (let ((type (treesit-node-type node)))
+ (while (setq node (treesit-node-parent node))
+ (when (equal (treesit-node-type node) type)
+ (throw 'term nil))))
+ t)))
+
(defun treesit-buffer-root-node (&optional language)
"Return the root node of the current buffer.
Use the first parser in (`treesit-parser-list'), if LANGUAGE is