Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Prototype of treesit.el support for ruby #47

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
**This is a WIP port of the original ts-fold library to work with Emacs 29's built in treesit.el. It is not fully tested, and will likely be eventually folded into the original library sometime after the Emacs 29 release**

[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![JCS-ELPA](https://raw.githubusercontent.com/jcs-emacs/badges/master/elpa/v/ts-fold.svg)](https://jcs-emacs.github.io/jcs-elpa/#/ts-fold)

Expand Down
8 changes: 4 additions & 4 deletions ts-fold-indicators.el
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,16 @@ Argument FOLDED holds folding state; it's a boolean."
"Refresh indicators for all folding range."
(when ts-fold-indicators-mode
(ts-fold--ensure-ts
(when-let* ((node (tsc-root-node tree-sitter-tree))
(when-let* ((node (treesit-buffer-root-node))
(patterns (seq-mapcat (lambda (fold-range) `((,(car fold-range)) @name))
(alist-get major-mode ts-fold-range-alist)
'vector))
(query (ignore-errors
(tsc-make-query tree-sitter-language patterns)))
(nodes-to-fold (tsc-query-captures query node #'ignore)))
(treesit-query-compile (treesit-node-language node)
(append patterns nil))))
(nodes-to-fold (treesit-query-capture node query nil nil t)))
(ts-fold-indicators--remove-overlays)
(thread-last nodes-to-fold
(mapcar #'cdr)
(mapc #'ts-fold-indicators--create))))))

(defun ts-fold-indicators--remove-overlays ()
Expand Down
8 changes: 7 additions & 1 deletion ts-fold-parsers.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
(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")
(declare-function ts-fold-range-yaml-object "ts-fold.el")

;;
;; (@* "Parsers" )
Expand Down Expand Up @@ -192,7 +193,7 @@
(compound_statement . ts-fold-range-seq)
(comment
. (lambda (node offset)
(if (string-prefix-p "#" (tsc-node-text node))
(if (string-prefix-p "#" (treesit-node-text node))
(ts-fold-range-line-comment node offset "#")
(ts-fold-range-c-like-comment node offset))))))

Expand Down Expand Up @@ -258,5 +259,10 @@
"Rule set for TypeScript."
(append (ts-fold-parsers-javascript)))

(defun ts-fold-parsers-yaml ()
"Rule set for YAML."
'((block_mapping_pair . ts-fold-range-yaml-object)))


(provide 'ts-fold-parsers)
;;; ts-fold-parsers.el ends here
19 changes: 19 additions & 0 deletions ts-fold-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@
(push ov lst)))
lst))

;;
;; (@* "Treesitter")
;;

(defun ts-fold--get-nth-child (node index)
(nth index (treesit-node-children node)))

(defun ts-fold--get-nth-named-child (node index)
(nth index (treesit-node-children node t)))

;;
;; (@* "Folds" )
;;

(defun ts-fold--get-fold-func (node)
(let ((fold-alist (alist-get major-mode ts-fold-range-alist))
(node-symbol (intern (treesit-node-type node))))
(alist-get node-symbol fold-alist)))

;;
;; (@* "Face" )
;;
Expand Down
Loading