branch: externals/indent-bars
commit d9459a784e0f41e543b4f79f1c17488b8f864975
Author: JD Smith <[email protected]>
Commit: JD Smith <[email protected]>
treesit improvements: always search from root node, add start-only
For string search, since query finds matching nodes which overlap in
any manner with the range specified, start-only means to use a null
range start-start, to ensure the matched item is not a sub-unit/child
of the node.
---
indent-bars.el | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/indent-bars.el b/indent-bars.el
index ec9af57113..2dbba3955d 100644
--- a/indent-bars.el
+++ b/indent-bars.el
@@ -825,12 +825,15 @@ see `indent-bars-prefer-character')."
(defvar-local indent-bars--ts-query nil)
(defvar-local indent-bars--ts-string-query nil)
-(defsubst indent-bars--ts-node-query (node query)
+(defsubst indent-bars--ts-node-query (node query &optional start-only)
"Capture node(s) spanning NODE matching QUERY.
-QUERY is a compiled treesit query."
- (treesit-query-capture
- indent-bars--ts-parser query
- (treesit-node-start node) (treesit-node-end node) t))
+QUERY is a compiled treesit query. If START-ONLY is non-nil, the
+query searches for matching nodes spanning the start of the node
+at point."
+ (let* ((start (treesit-node-start node))
+ (end (if start-only start (treesit-node-end node))))
+ (treesit-query-capture (treesit-buffer-root-node) query
+ start end t)))
(defsubst indent-bars--indent-at-node (node)
"Return the current indentation at the start of NODE."
@@ -857,7 +860,7 @@ than the starting line's depth."
(node (treesit-node-on (1- p) p
indent-bars--ts-parser)))
(if (and indent-bars-no-descend-string
(indent-bars--ts-node-query
- node indent-bars--ts-string-query))
+ node indent-bars--ts-string-query t))
(1+ (indent-bars--depth (indent-bars--indent-at-node
node)))
(when-let ((ctx (indent-bars--ts-node-query
node indent-bars--ts-query)))