-
-
Notifications
You must be signed in to change notification settings - Fork 30
Closed
Description
I'm considering adding a feature that allows custom folding through a tree-sitter sexp query (validated by the tree-siter-query-builder). With some initial attempts, I couldn't get it working. Would anyone be able to take a look and see if it's possible to implement this feature? (or at least let me know what goes wrong with my approach?)
My steps:
- Appending custom queries by
vconcatwithrange-patterns. Please see my code here - In Emacs init file, you add the following snippets:
(setq ts-fold-pattern-alist
'((python-mode . (((argument_list) @name (\#match? @name "\"[^\\n]*\\n+[^\\n]*\""))))))- Update the
tsc--stringify-patternsfunction of tsc.el to:
(defun tsc--stringify-patterns (patterns)
"Convert PATTERNS into a query string that can be passed to `tsc--make-query'."
(cond
((stringp patterns) patterns)
((sequencep patterns)
;; XXX: This is hacky.
(thread-last (mapconcat (lambda (p) (format "%S" p)) patterns "\n")
(replace-regexp-in-string (regexp-quote "\\?") "?")
(replace-regexp-in-string (regexp-quote "\\.") ".")
(replace-regexp-in-string (regexp-quote "\\n") "\n")
(replace-regexp-in-string (regexp-quote "\\#") "#")))
(t (error "Invalid patterns"))))Outcome:
- Parsing seems to work. If I add
(message (format patterns))before this (line)[https://github.com/emacs-tree-sitter/elisp-tree-sitter/blob/master/core/tsc.el#L242], I will get[(function_definition) @name (class_definition) @name (list) @name (dictionary) @name (comment) @name ((argument_list) @name (#match? @name "[^\n]*\n+[^\n]*")) @name] - But I got this error:
Error: (tsc-query-invalid-node-type "" (11 . 1) 103). It seems tsc is returning invalid nodes, which confused me. The sexp query above works well withtree-siter-query-builder.
Any thoughts?
Metadata
Metadata
Assignees
Labels
No labels