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)
|
||||
(setq foldable-node-types
|
||||
(append foldable-node-types
|
||||
'("block" "then" "else"))))
|
||||
'("block" "then" "else" "pair"))))
|
||||
(when (>= level 3)
|
||||
(setq foldable-node-types
|
||||
(append foldable-node-types
|
||||
@ -126,7 +126,9 @@
|
||||
(or (not (equal (treesit-node-type node) "call"))
|
||||
(treesit-node-child-by-field-name node "arguments"))
|
||||
(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
|
||||
(lambda (node)
|
||||
(pcase (treesit-node-type node)
|
||||
@ -163,10 +165,17 @@
|
||||
(list start end offset child-nodes)))
|
||||
("call" (let* ((args (treesit-node-child-by-field-name node "arguments"))
|
||||
(method (treesit-node-child-by-field-name node "method"))
|
||||
(start (treesit-node-start method))
|
||||
(end (- (treesit-node-end args) 1))
|
||||
(offset (1+ (- (treesit-node-start args) start)))
|
||||
(child-nodes (list args))
|
||||
(start (treesit-node-start node))
|
||||
(end (if (equal (char-before (treesit-node-end args)) ?\))
|
||||
(- (treesit-node-end args) 1)
|
||||
(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
|
||||
((block
|
||||
(treesit-node-child-by-field-name node "block")))
|
||||
@ -182,7 +191,13 @@
|
||||
(end (treesit-node-end node))
|
||||
(offset (- (treesit-node-start right) start))
|
||||
(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
|
||||
(add-to-list 'origami-parser-alist '(yaml-ts-mode . origami-yaml-treesit-parser))
|
||||
|
Loading…
Reference in New Issue
Block a user