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

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

[nongnu] elpa/treesit-fold 630b896b3f 277/417: feat: Add Haskell support


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold 630b896b3f 277/417: feat: Add Haskell support (#65)
Date: Mon, 1 Jul 2024 10:02:35 -0400 (EDT)

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

    feat: Add Haskell support (#65)
    
    * feat: Add Haskell support
    
    * simp
    
    * changelog
    
    * fix compile
---
 CHANGELOG.md       |  2 ++
 README.md          |  2 +-
 ts-fold-parsers.el |  6 ++++++
 ts-fold-summary.el |  1 +
 ts-fold-util.el    |  6 ++++++
 ts-fold.el         | 20 +++++++++++++++-----
 6 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 291a43c9d6..b6f08fd5fa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for 
recommendations on how
 * Add support for Python docstring (#58)
 * Add Dart support (#62)
 * Add Elisp support (#63)
+* Add Clojure support (#64)
+* Add Haskell support (#65)
 
 ## 0.1.0
 > Released Oct 18, 2021
diff --git a/README.md b/README.md
index 403087c0c1..b7d075db77 100644
--- a/README.md
+++ b/README.md
@@ -117,7 +117,7 @@ These languages are fairly complete:
 - Dart
 - Elisp / Elixir
 - Go
-- HTML
+- Haskell / HTML
 - Java / JavaScript / JSX / JSON / Julia
 - Lua
 - Nix
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index 02c4cbb5cc..17916a4708 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -44,6 +44,7 @@
 (declare-function ts-fold-range-c-preproc-if "ts-fold.el")
 (declare-function ts-fold-range-c-preproc-elif "ts-fold.el")
 (declare-function ts-fold-range-c-preproc-else "ts-fold.el")
+(declare-function ts-fold-range-haskell-function "ts-fold.el")
 (declare-function ts-fold-range-html "ts-fold.el")
 (declare-function ts-fold-range-julia "ts-fold.el")
 (declare-function ts-fold-range-lua-comment "ts-fold.el")
@@ -167,6 +168,11 @@
     (interface_type         . (lambda (node offset)
                                 (ts-fold-range-markers node offset "{" "}")))))
 
+(defun ts-fold-parsers-haskell ()
+  "Rule set for Haskell."
+  '((function . ts-fold-range-haskell-function)
+    (comment  . ts-fold-range-lua-comment)))
+
 (defun ts-fold-parsers-html ()
   "Rule set for HTML."
   '((element . ts-fold-range-html)
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index a3360741fe..b6eff07665 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -213,6 +213,7 @@ type of content by checking the word boundary's existence."
     (dart-mode         . ts-fold-summary-javadoc)
     (emacs-lisp-mode   . ts-fold-summary-elisp)
     (go-mode           . ts-fold-summary-go)
+    (haskell-mode      . ts-fold-summary-lua-doc)
     (html-mode         . ts-fold-summary-xml)
     (java-mode         . ts-fold-summary-javadoc)
     (javascript-mode   . ts-fold-summary-javadoc)
diff --git a/ts-fold-util.el b/ts-fold-util.el
index b3500c612a..58face2122 100644
--- a/ts-fold-util.el
+++ b/ts-fold-util.el
@@ -133,5 +133,11 @@ information."
         (setq parent (tsc-get-parent parent))))
     parent))
 
+(defun ts-fold-last-child (node)
+  "Return last child node from parent NODE."
+  (when-let* ((count (tsc-count-children node))
+              ((not (= count 0))))
+    (tsc-get-nth-child node (1- count))))
+
 (provide 'ts-fold-util)
 ;;; ts-fold-util.el ends here
diff --git a/ts-fold.el b/ts-fold.el
index dd8cba6d2a..87f2b20ec2 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -71,6 +71,7 @@
     (elixir-mode     . ,(ts-fold-parsers-elixir))
     (ess-r-mode      . ,(ts-fold-parsers-r))
     (go-mode         . ,(ts-fold-parsers-go))
+    (haskell-mode    . ,(ts-fold-parsers-haskell))
     (html-mode       . ,(ts-fold-parsers-html))
     (java-mode       . ,(ts-fold-parsers-java))
     (javascript-mode . ,(ts-fold-parsers-javascript))
@@ -532,13 +533,24 @@ more information."
               (end (1- (tsc-node-start-position next))))
     (ts-fold--cons-add (cons beg end) offset)))
 
+(defun ts-fold-range-haskell-function (node offset)
+  "Define fold range for `function' in Haskell.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (when-let* ((beg (tsc-node-start-position node))
+              (beg (save-excursion (goto-char beg) (line-end-position)))
+              (end-node (ts-fold-last-child node))
+              (end (tsc-node-end-position end-node)))
+    (ts-fold--cons-add (cons beg end) offset)))
+
 (defun ts-fold-range-html (node offset)
   "Define fold range for tag in HTML.
 
 For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
 more information."
   (let* ((beg (tsc-node-end-position (tsc-get-nth-child node 0)))
-         (end-node (tsc-get-nth-child node (1- (tsc-count-children node))))
+         (end-node (ts-fold-last-child node))
          (end (tsc-node-start-position end-node)))
     (ts-fold--cons-add (cons beg end) offset)))
 
@@ -675,8 +687,7 @@ more information."
 
 For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
 more information."
-  (when-let* ((children (tsc-count-children node))
-              (last_bracket (tsc-get-nth-child node (- children 1)))
+  (when-let* ((last_bracket (ts-fold-last-child node))
               (first_bracket (tsc-get-nth-child node 2))
               (beg (tsc-node-start-position first_bracket))
               (end (1+ (tsc-node-start-position last_bracket))))
@@ -698,8 +709,7 @@ more information."
 
 For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
 more information."
-  (when-let* ((children (tsc-count-children node))
-              (end_child (tsc-get-nth-child node (- children 1)))
+  (when-let* ((end_child (ts-fold-last-child node))
               (do_child (tsc-get-nth-child node 1))
               (beg (tsc-node-start-position do_child))
               (end (tsc-node-start-position end_child)))



reply via email to

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