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

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

[nongnu] elpa/treesit-fold 8fc88e29f5 089/417: Login update for Csharp c


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold 8fc88e29f5 089/417: Login update for Csharp comment
Date: Mon, 1 Jul 2024 10:02:14 -0400 (EDT)

branch: elpa/treesit-fold
commit 8fc88e29f5725b2ff3f593d245013ff3cc9c79d5
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: Jen-Chieh Shen <jcs090218@gmail.com>

    Login update for Csharp comment
---
 tree-sitter-fold-parsers.el |  7 +++----
 tree-sitter-fold-summary.el |  8 +++++++-
 tree-sitter-fold.el         | 16 +++++++++++++---
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/tree-sitter-fold-parsers.el b/tree-sitter-fold-parsers.el
index eeb1472b2e..077d6bf5ec 100644
--- a/tree-sitter-fold-parsers.el
+++ b/tree-sitter-fold-parsers.el
@@ -64,7 +64,7 @@
     (switch_body                          . tree-sitter-fold-range-seq)
     (anonymous_object_creation_expression . tree-sitter-fold-range-seq)
     (initializer_expression               . tree-sitter-fold-range-seq)
-    (comment                              . (tree-sitter-fold-range-seq 1 
-1))))
+    (comment                              . 
tree-sitter-fold-range-csharp-comment)))
 
 (defun tree-sitter-fold-parsers-css ()
   "Rule sets for CSS."
@@ -73,9 +73,8 @@
 
 (defun tree-sitter-fold-parsers-go ()
   "Rule sets for Go."
-  '((type_declaration     . tree-sitter-fold-range-go-type-declaration)
-    (function_declaration . tree-sitter-fold-range-go-method)
-    (method_declaration   . tree-sitter-fold-range-go-method)))
+  '((block   . tree-sitter-fold-range-seq)
+    (comment . tree-sitter-fold-range-seq)))
 
 (defun tree-sitter-fold-parsers-html ()
   "Rule sets for HTML."
diff --git a/tree-sitter-fold-summary.el b/tree-sitter-fold-summary.el
index 802159f05f..086ffc6acd 100644
--- a/tree-sitter-fold-summary.el
+++ b/tree-sitter-fold-summary.el
@@ -106,6 +106,12 @@ type of content by checking the word boundary's existence."
     (setq doc-str (s-replace-regexp "<[/]*[^>]+." "" doc-str))
     (tree-sitter-fold-summary--generic doc-str (if type-triple "///" "//"))))
 
+(defun tree-sitter-fold-summary-csharp (doc-str)
+  "Extract summary for C# from DOC-STR."
+  (or (tree-sitter-fold-summary-javadoc doc-str)
+      (tree-sitter-fold-summary-csharp-vsdoc doc-str)
+      (tree-sitter-fold-summary-c-macro doc-str)))
+
 (defun tree-sitter-fold-summary-javadoc (doc-str)
   "Extract javadoc summary from DOC-STR."
   (tree-sitter-fold-summary--generic doc-str "*"))
@@ -189,7 +195,7 @@ type of content by checking the word boundary's existence."
     (bat-mode          . tree-sitter-fold-summary-batch)
     (c-mode            . tree-sitter-fold-summary-c)
     (c++-mode          . tree-sitter-fold-summary-c)
-    (csharp-mode       . tree-sitter-fold-summary-csharp-vsdoc)
+    (csharp-mode       . tree-sitter-fold-summary-csharp)
     (go-mode           . tree-sitter-fold-summary-go)
     (java-mode         . tree-sitter-fold-summary-javadoc)
     (javascript-mode   . tree-sitter-fold-summary-javadoc)
diff --git a/tree-sitter-fold.el b/tree-sitter-fold.el
index f3b5cfbd92..7fe2d368ca 100644
--- a/tree-sitter-fold.el
+++ b/tree-sitter-fold.el
@@ -321,6 +321,10 @@ If the current syntax node is not foldable, do nothing."
 ;; (@* "Languages" )
 ;;
 
+(defun tree-sitter-fold-multi-line (node)
+  "Return t, if content NODE is single line."
+  (string-match-p "\n" (tsc-node-text node)))
+
 (defun tree-sitter-fold-range-seq (node offset)
   "Return the fold range in sequence."
   (let ((beg (1+ (tsc-node-start-position node)))
@@ -328,8 +332,14 @@ If the current syntax node is not foldable, do nothing."
     (setq beg (+ beg (car offset)) end (+ end (cdr offset)))
     (cons beg end)))
 
+(defun tree-sitter-fold-range-csharp-comment (node offset)
+  "Define fold range for C# comment."
+  (if (tree-sitter-fold-multi-line node)
+      (tree-sitter-fold-range-seq node (cons 1 -1))
+    nil))
+
 (defun tree-sitter-fold-range-go-type-declaration (node offset)
-  "Return the fold range for `type_declaration' NODE in Go language.
+  "Return the fold range for `type_declaration' NODE.
 Only `struct_type' and `interface_type' nodes can be folded."
   (when-let* ((type-spec-node (tsc-get-nth-child node 1))
               ;; the type_spec node is not named in the Go grammar
@@ -349,7 +359,7 @@ Only `struct_type' and `interface_type' nodes can be 
folded."
      (t nil))))
 
 (defun tree-sitter-fold-range-go-method (node offset)
-  "Return the fold range for `method_declaration' NODE in Go language."
+  "Return the fold range for `method_declaration' NODE."
   (let* ((named-node (or (tsc-get-child-by-field node :result)
                          (tsc-get-child-by-field node :parameters)))
          (beg (1+ (tsc-node-end-position named-node)))
@@ -358,7 +368,7 @@ Only `struct_type' and `interface_type' nodes can be 
folded."
     (cons beg end)))
 
 (defun tree-sitter-fold-range-nix-function (node offset)
-  "Return the fold range for `function' NODE in Nix express language."
+  "Return the fold range for `function' NODE."
   (let ((beg (thread-first node
                (tsc-get-child-by-field :formals)
                (tsc-get-next-sibling)



reply via email to

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