branch: elpa/treesit-fold
commit 4b35e27148e7f45e965752062314b7c3e7bf8dc2
Author: Jen-Chieh Shen <[email protected]>
Commit: GitHub <[email protected]>
feat: Add SQL support (#91)
---
CHANGELOG.md | 1 +
README.md | 2 +-
ts-fold-parsers.el | 11 ++++++++++-
ts-fold-summary.el | 1 +
ts-fold.el | 14 +++++++++++++-
5 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7b87ced22d..4d791c0f31 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for
recommendations on how
* perf: Speed up count matches (#88)
* Add reStructuredText support (#89)
* Add Make support (#90)
+* Add SQL support (#91)
## 0.2.0
> Released Sep 01, 2023
diff --git a/README.md b/README.md
index dfda4bad6b..d914872984 100644
--- a/README.md
+++ b/README.md
@@ -127,7 +127,7 @@ These languages are fairly complete:
- OCaml
- Perl / PHP / Python
- R / Ruby / Rust / reStructuredText
-- Scala / Scheme / Swift
+- Scala / Scheme / SQL / Swift
- TOML / TypeScript / TSX
- Verilog / VHDL
- XML
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index 141311cc40..0b3193c472 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -70,8 +70,10 @@
(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-sql-block "ts-fold.el")
(declare-function ts-fold-range-toml-table "ts-fold.el")
(declare-function ts-fold-range-verilog-list "ts-fold.el")
+(declare-function ts-fold-range-verilog-initial-construct "ts-fold.el")
(declare-function ts-fold-range-verilog-module "ts-fold.el")
(declare-function ts-fold-range-vhdl-package "ts-fold.el")
(declare-function ts-fold-range-vhdl-type "ts-fold.el")
@@ -432,6 +434,13 @@
. (lambda (node offset)
(ts-fold-range-line-comment node offset ";;")))))
+(defun ts-fold-parsers-sql ()
+ "Rule set for SQL."
+ '((block . ts-fold-range-sql-block)
+ (subquery . ts-fold-range-seq)
+ (list . ts-fold-range-seq)
+ (marginalia . ts-fold-range-c-like-comment))) ; This is the comment!
+
(defun ts-fold-parsers-swift ()
"Rule set for Swift."
'((switch_statement . ts-fold-range-seq)
@@ -464,7 +473,7 @@
"Rule set for Verilog."
'((module_declaration . ts-fold-range-verilog-module)
(list_of_port_connections . ts-fold-range-verilog-list)
- (initial_construct . ts-fold-range-initial-construct)
+ (initial_construct . ts-fold-range-verilog-initial-construct)
(comment . ts-fold-range-c-like-comment)))
(defun ts-fold-parsers-vhdl ()
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index a9c6747f18..ee416582a8 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -270,6 +270,7 @@ type of content by checking the word boundary's existence."
(scala-mode . ts-fold-summary-javadoc)
(scheme-mode . ts-fold-summary-elisp)
(sh-mode . ts-fold-summary-javadoc)
+ (sql-mode . ts-fold-summary-c)
(swift-mode . ts-fold-summary-c)
(toml-mode . ts-fold-summary-javadoc)
(conf-toml-mode . ts-fold-summary-javadoc)
diff --git a/ts-fold.el b/ts-fold.el
index 9ee03ce68b..ad9b61eeff 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -115,6 +115,7 @@
(scheme-mode . ,(ts-fold-parsers-scheme))
(sh-mode . ,(ts-fold-parsers-bash))
(scala-mode . ,(ts-fold-parsers-scala))
+ (sql-mode . ,(ts-fold-parsers-sql))
(swift-mode . ,(ts-fold-parsers-swift))
(toml-mode . ,(ts-fold-parsers-toml))
(conf-toml-mode . ,(ts-fold-parsers-toml))
@@ -974,6 +975,17 @@ more information."
(end (1+ (tsc-node-start-position last_bracket))))
(ts-fold--cons-add (cons beg end) offset)))
+(defun ts-fold-range-sql-block (node offset)
+ "Return the fold range for `block' in SQL.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+ (when-let* ((beg-node (car (ts-fold-find-children node "keyword_begin")))
+ (end-node (car (ts-fold-find-children node "keyword_end")))
+ (beg (tsc-node-end-position beg-node))
+ (end (tsc-node-start-position end-node)))
+ (ts-fold--cons-add (cons beg end) offset)))
+
(defun ts-fold-range-toml-table (node offset)
"Return the fold range for `table' in TOML.
@@ -985,7 +997,7 @@ more information."
(end (tsc-node-end-position end-child)))
(ts-fold--cons-add (cons beg end) offset)))
-(defun ts-fold-range-initial-construct (node offset)
+(defun ts-fold-range-verilog-initial-construct (node offset)
"Return the fold range for `initial' in Verilog.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for