emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/treesit-fold 443ba5106a 229/417: feat(ruby): Enhance Ruby


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold 443ba5106a 229/417: feat(ruby): Enhance Ruby parser (#26)
Date: Mon, 1 Jul 2024 10:02:29 -0400 (EDT)

branch: elpa/treesit-fold
commit 443ba5106ab201e7be507680b734194f2097e8f3
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: GitHub <noreply@github.com>

    feat(ruby): Enhance Ruby parser (#26)
    
    * feat(ruby): Add fold range for do_block node
    
    * feat(ruby): support if, elsif, and else
---
 ts-fold-parsers.el | 13 +++++++++----
 ts-fold.el         | 11 ++++++++++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index 5a9cd4cc31..35b4fbb216 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -47,7 +47,8 @@
 (declare-function ts-fold-range-html "ts-fold.el")
 (declare-function ts-fold-range-ocaml "ts-fold.el")
 (declare-function ts-fold-range-python "ts-fold.el")
-(declare-function ts-fold-range-ruby "ts-fold.el")
+(declare-function ts-fold-range-ruby-class-def "ts-fold.el")
+(declare-function ts-fold-range-ruby-if "ts-fold.el")
 (declare-function ts-fold-range-rust-macro "ts-fold.el")
 (declare-function ts-fold-range-elixir "ts-fold.el")
 
@@ -194,9 +195,13 @@
 
 (defun ts-fold-parsers-ruby ()
   "Rule set for Ruby."
-  '((class  . ts-fold-range-ruby)
-    (method . ts-fold-range-ruby)
-    (array  . ts-fold-range-seq)
+  '((class    . ts-fold-range-ruby-class-def)
+    (method   . ts-fold-range-ruby-class-def)
+    (array    . ts-fold-range-seq)
+    (do       . (ts-fold-range-seq 1 -2))  ; match with `end`
+    (do_block . (ts-fold-range-seq 1 -2))  ; match with `end`, in spec file
+    (then     . ts-fold-range-ruby-if)        ; `if` and `elsif` block
+    (else     . (ts-fold-range-ruby-if 4 0))  ; `else` block
     (comment
      . (lambda (node offset)
          (ts-fold-range-line-comment node offset "#")))))
diff --git a/ts-fold.el b/ts-fold.el
index 4a6f509a91..e1655dc615 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -550,7 +550,7 @@ more information."
               (end (tsc-node-end-position node)))
     (ts-fold--cons-add (cons beg end) offset)))
 
-(defun ts-fold-range-ruby (node offset)
+(defun ts-fold-range-ruby-class-def (node offset)
   "Define fold range for `method' and `class' in Ruby.
 
 For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
@@ -560,6 +560,15 @@ more information."
                               (tsc-get-child-by-field node :name)))
               (beg (tsc-node-end-position named-node))
               (end (tsc-node-end-position node)))
+    (ts-fold--cons-add (cons beg (- end 3)) offset)))
+
+(defun ts-fold-range-ruby-if (node offset)
+  "Define fold range for `if' (then), `elsif', and `else' in Ruby.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (when-let ((beg (tsc-node-start-position node))
+             (end (tsc-node-end-position node)))
     (ts-fold--cons-add (cons beg end) offset)))
 
 (defun ts-fold-range-rust-macro (node offset)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]