Add folding for ruby hash pairs and fix folding for calls
This commit is contained in:
parent
a0c0f6d1e2
commit
889abf2606
@ -105,7 +105,7 @@
|
|||||||
(when (>= level 2)
|
(when (>= level 2)
|
||||||
(setq foldable-node-types
|
(setq foldable-node-types
|
||||||
(append foldable-node-types
|
(append foldable-node-types
|
||||||
'("block" "then" "else"))))
|
'("block" "then" "else" "pair"))))
|
||||||
(when (>= level 3)
|
(when (>= level 3)
|
||||||
(setq foldable-node-types
|
(setq foldable-node-types
|
||||||
(append foldable-node-types
|
(append foldable-node-types
|
||||||
@ -126,7 +126,9 @@
|
|||||||
(or (not (equal (treesit-node-type node) "call"))
|
(or (not (equal (treesit-node-type node) "call"))
|
||||||
(treesit-node-child-by-field-name node "arguments"))
|
(treesit-node-child-by-field-name node "arguments"))
|
||||||
(or (not (member (treesit-node-type node) '("then" "else")))
|
(or (not (member (treesit-node-type node) '("then" "else")))
|
||||||
(treesit-node-children node)))))
|
(treesit-node-children node))
|
||||||
|
(or (not (equal (treesit-node-type node) "pair"))
|
||||||
|
(treesit-node-child-by-field-name node "value")))))
|
||||||
:fold-fn
|
:fold-fn
|
||||||
(lambda (node)
|
(lambda (node)
|
||||||
(pcase (treesit-node-type node)
|
(pcase (treesit-node-type node)
|
||||||
@ -163,10 +165,17 @@
|
|||||||
(list start end offset child-nodes)))
|
(list start end offset child-nodes)))
|
||||||
("call" (let* ((args (treesit-node-child-by-field-name node "arguments"))
|
("call" (let* ((args (treesit-node-child-by-field-name node "arguments"))
|
||||||
(method (treesit-node-child-by-field-name node "method"))
|
(method (treesit-node-child-by-field-name node "method"))
|
||||||
(start (treesit-node-start method))
|
(start (treesit-node-start node))
|
||||||
(end (- (treesit-node-end args) 1))
|
(end (if (equal (char-before (treesit-node-end args)) ?\))
|
||||||
(offset (1+ (- (treesit-node-start args) start)))
|
(- (treesit-node-end args) 1)
|
||||||
(child-nodes (list args))
|
(treesit-node-end args)))
|
||||||
|
(offset (if (equal (char-after (treesit-node-start args)) ?\()
|
||||||
|
(1+ (- (treesit-node-start args) start))
|
||||||
|
(- (treesit-node-start args) start)))
|
||||||
|
(child-nodes (-filter (lambda (n)
|
||||||
|
(not (equal (treesit-node-field-name n)
|
||||||
|
"block")))
|
||||||
|
(treesit-node-children node)))
|
||||||
(sibling-nodes (when-let
|
(sibling-nodes (when-let
|
||||||
((block
|
((block
|
||||||
(treesit-node-child-by-field-name node "block")))
|
(treesit-node-child-by-field-name node "block")))
|
||||||
@ -182,7 +191,13 @@
|
|||||||
(end (treesit-node-end node))
|
(end (treesit-node-end node))
|
||||||
(offset (- (treesit-node-start right) start))
|
(offset (- (treesit-node-start right) start))
|
||||||
(child-nodes (list right)))
|
(child-nodes (list right)))
|
||||||
(list start end offset child-nodes)))))))
|
(list start end offset child-nodes)))
|
||||||
|
("pair" (let* ((value (treesit-node-child-by-field-name node "value"))
|
||||||
|
(start (treesit-node-start node))
|
||||||
|
(end (treesit-node-end node))
|
||||||
|
(offset (- (treesit-node-start value) start))
|
||||||
|
(child-nodes (list value)))
|
||||||
|
(list start end offset child-nodes)))))))
|
||||||
|
|
||||||
(with-eval-after-load 'origami
|
(with-eval-after-load 'origami
|
||||||
(add-to-list 'origami-parser-alist '(yaml-ts-mode . origami-yaml-treesit-parser))
|
(add-to-list 'origami-parser-alist '(yaml-ts-mode . origami-yaml-treesit-parser))
|
||||||
|
Loading…
Reference in New Issue
Block a user