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

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

[nongnu] elpa/treesit-fold 342eb5ee1f 324/417: fix: Don't render indicat


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold 342eb5ee1f 324/417: fix: Don't render indicators on non foldable node
Date: Mon, 1 Jul 2024 10:02:59 -0400 (EDT)

branch: elpa/treesit-fold
commit 342eb5ee1f242ac03bc7e7bbe8d67be8711423ae
Author: JenChieh <jcs090218@gmail.com>
Commit: JenChieh <jcs090218@gmail.com>

    fix: Don't render indicators on non foldable node
---
 ts-fold-indicators.el |  9 ++++--
 ts-fold.el            | 76 +++++++++++++++++++++++----------------------------
 2 files changed, 41 insertions(+), 44 deletions(-)

diff --git a/ts-fold-indicators.el b/ts-fold-indicators.el
index 4eeed1a650..5956ff47b6 100644
--- a/ts-fold-indicators.el
+++ b/ts-fold-indicators.el
@@ -283,7 +283,7 @@ Argument FOLDED holds folding state; it's a boolean."
       (ts-fold-indicators--create-overlays beg end folded))))
 
 (defun ts-fold-indicators--size-change (&optional frame &rest _)
-  "Render indicators for all visible windows."
+  "Render indicators for all visible windows from FRAME."
   (ts-fold--with-no-redisplay
     (dolist (win (window-list frame)) (ts-fold-indicators--render-window 
win))))
 
@@ -320,7 +320,12 @@ Argument FOLDED holds folding state; it's a boolean."
            (nodes-to-fold
             (cl-remove-if-not (lambda (node)
                                 (ts-fold--within-window (cdr node) wend 
wstart))
-                              nodes-to-fold)))
+                              nodes-to-fold))
+           (mode-ranges (alist-get major-mode ts-fold-range-alist))
+           (nodes-to-fold
+            (cl-remove-if (lambda (node)
+                            (ts-fold--non-foldable-node-p (cdr node) 
mode-ranges))
+                          nodes-to-fold)))
         (ts-fold-indicators--remove-ovs)
         (thread-last nodes-to-fold
                      (mapcar #'cdr)
diff --git a/ts-fold.el b/ts-fold.el
index e1527e7565..e5b31a4351 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -274,8 +274,8 @@ Return nil if there is no fold to be made."
           ((listp fold-func) (funcall (nth 0 fold-func) node (cons (nth 1 
fold-func) (nth 2 fold-func))))
           (t (user-error "Bad folding function for node")))))
 
-(defun ts-fold--foldable-node-p (node mode-ranges)
-  "Return non-nil if NODE is foldable in MODE-RANGES."
+(defun ts-fold--non-foldable-node-p (node mode-ranges)
+  "Return non-nil if NODE is a non-foldable in MODE-RANGES."
   (or (not (alist-get (tsc-node-type node) mode-ranges))  ; Not registered, 
continue.
       (let ((range (ts-fold--get-fold-range node)))
         (or (not range)                                   ; Range not defined, 
continue.
@@ -294,7 +294,7 @@ This function is borrowed from `tree-sitter-node-at-point'."
          ;; Used for looping
          (current node))
     (while (and current
-                (ts-fold--foldable-node-p current mode-ranges))
+                (ts-fold--non-foldable-node-p current mode-ranges))
       (setq current (tsc-get-parent current)))
     current))
 
@@ -474,10 +474,6 @@ in backward direction."
       (setq iter-node (ts-fold--next-prev-node-skip-newline iter-node next)))
     last-node))
 
-(defun ts-fold--one-liner-node (node)
-  "Helper function to check if NODE is on one line only."
-  (= (car (aref (tsc-node-range node) 2)) (car (aref (tsc-node-range node) 
3))))
-
 (defun ts-fold-range-seq (node offset)
   "Return the fold range in sequence starting from NODE.
 
@@ -893,59 +889,55 @@ more information."
 
 For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
 more information."
-  (unless (ts-fold--one-liner-node node)
-    (when-let* ((text (tsc-node-text node))
-                (beg  (+ (if (string-prefix-p "(* " text) 2 3)
-                         (tsc-node-start-position node)))
-                (end  (- (tsc-node-end-position node) 2)))
-      (ts-fold--cons-add (cons beg end) offset))))
+  (when-let* ((text (tsc-node-text node))
+              (beg  (+ (if (string-prefix-p "(* " text) 2 3)
+                       (tsc-node-start-position node)))
+              (end  (- (tsc-node-end-position node) 2)))
+    (ts-fold--cons-add (cons beg end) offset)))
 
 (defun ts-fold-range-ocaml-module-definition (node offset)
   "Define fold range for `module_definition'.
 
 For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
 more information."
-  (unless (ts-fold--one-liner-node node)
-    (when-let*
-        ((module-binding (tsc-get-nth-named-child node 0))
-         (body           (tsc-get-child-by-field module-binding :body))
-         ;; body is struct ... end
-         (beg            (+ 6 (tsc-node-start-position body)))
-         (end            (- (tsc-node-end-position node) 3)))
-      (ts-fold--cons-add (cons beg end) offset))))
+  (when-let*
+      ((module-binding (tsc-get-nth-named-child node 0))
+       (body           (tsc-get-child-by-field module-binding :body))
+       ;; body is struct ... end
+       (beg            (+ 6 (tsc-node-start-position body)))
+       (end            (- (tsc-node-end-position node) 3)))
+    (ts-fold--cons-add (cons beg end) offset)))
 
 (defun ts-fold-range-ocaml-type-definition (node offset)
   "Define fold range for `type_definition'.
 
 For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
 more information."
-  (unless (ts-fold--one-liner-node node)
-    (when-let*
-        ((type-definition (tsc-get-nth-named-child node 0))
-         (body            (tsc-get-child-by-field type-definition :body))
-         (text            (tsc-node-text (tsc-get-nth-child body 0)))
-         (beg
-          (if (string-equal "{" text)
-              (1+ (tsc-node-start-position body))
-            (tsc-node-end-position (tsc-get-prev-sibling body))))
-         (end
-          (if (string-equal "{" text)
-              (1- (tsc-node-end-position node))
-            (tsc-node-end-position node))))
-      (ts-fold--cons-add (cons beg end) offset))))
+  (when-let*
+      ((type-definition (tsc-get-nth-named-child node 0))
+       (body            (tsc-get-child-by-field type-definition :body))
+       (text            (tsc-node-text (tsc-get-nth-child body 0)))
+       (beg
+        (if (string-equal "{" text)
+            (1+ (tsc-node-start-position body))
+          (tsc-node-end-position (tsc-get-prev-sibling body))))
+       (end
+        (if (string-equal "{" text)
+            (1- (tsc-node-end-position node))
+          (tsc-node-end-position node))))
+    (ts-fold--cons-add (cons beg end) offset)))
 
 (defun ts-fold-range-ocaml-value-definition (node offset)
   "Define fold range for `value_definition'.
 
 For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
 more information."
-  (unless (ts-fold--one-liner-node node)
-    (when-let*
-        ((let-binding  (tsc-get-nth-named-child node 0))
-         (body         (tsc-get-child-by-field let-binding :body))
-         (beg          (tsc-node-end-position (tsc-get-prev-sibling body)))
-         (end          (tsc-node-end-position node)))
-      (ts-fold--cons-add (cons beg end) offset))))
+  (when-let*
+      ((let-binding  (tsc-get-nth-named-child node 0))
+       (body         (tsc-get-child-by-field let-binding :body))
+       (beg          (tsc-node-end-position (tsc-get-prev-sibling body)))
+       (end          (tsc-node-end-position node)))
+    (ts-fold--cons-add (cons beg end) offset)))
 
 ;;- OCaml
 



reply via email to

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