mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-03 02:31:03 -08:00
Improve treesit settings for js-ts-mode (bug#73404)
* lisp/progmodes/js.el (js--treesit-font-lock-settings): Add 'class' alongside 'class_declaration'. (js--treesit-defun-name): Add "variable_declaration" alongside "lexical_declaration". (js--treesit-valid-imenu-entry): Add "variable_declaration" and provide the predicate to 'treesit-node-top-level'. (js--treesit-sentence-nodes): Add "jsx_attribute" like in html-ts-mode instead of jsx elements matched in 'js--treesit-list-nodes'. (js--treesit-list-nodes): Add "jsx_element" and "jsx_self_closing_element" instead of "_jsx_string". (js--treesit-simple-imenu-settings): Move "method_definition" to separate section "Method" from the "Class" section. Add "variable_declaration" to the "Variable" section. (js-ts-mode--outline-predicate): New variable. (js--treesit-defun-type-regexp): Add bos/eos. (js--treesit-jsdoc-comment-regexp): Add bos/eos. (js-ts-mode): Set treesit-outline-predicate to 'js-ts-mode--outline-predicate'. * lisp/textmodes/mhtml-ts-mode.el (mhtml-ts-mode--html-defun-name): Remove unused function. (mhtml-ts-mode): Use 'js-ts-mode--outline-predicate' in 'treesit-aggregated-outline-predicate'. * lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode--outline-predicate): Use 'treesit-node-top-level' instead of 'treesit-parent-until'.
This commit is contained in:
parent
10abb87f05
commit
dbc0e5a52d
3 changed files with 41 additions and 30 deletions
|
|
@ -367,15 +367,6 @@ NODE and PARENT are ignored."
|
|||
(defvar mhtml-ts-mode--prettify-symbols-alist js--prettify-symbols-alist
|
||||
"Alist of symbol prettifications for various supported languages.")
|
||||
|
||||
(defun mhtml-ts-mode--html-defun-name (node)
|
||||
"Return the defun name of NODE.
|
||||
Return nil if there is no name or if NODE is not a defun node."
|
||||
(when (string-match-p "element" (treesit-node-type node))
|
||||
(treesit-node-text
|
||||
node
|
||||
;; (treesit-search-subtree node "\\`tag_name\\'" nil nil 2)
|
||||
t)))
|
||||
|
||||
;; In order to support `which-fuction-mode' we should define
|
||||
;; a function that return the defun name.
|
||||
;; In a multilingual treesit mode, this can be implemented simply by
|
||||
|
|
@ -584,8 +575,7 @@ Powered by tree-sitter."
|
|||
|
||||
(setq-local treesit-aggregated-outline-predicate
|
||||
`((html . ,#'html-ts-mode--outline-predicate)
|
||||
;; TODO: add a predicate like for html above
|
||||
(javascript . "\\`function_declaration\\'")
|
||||
(javascript . ,js-ts-mode--outline-predicate)
|
||||
(css . ,css-ts-mode--outline-predicate)))
|
||||
|
||||
(treesit-major-mode-setup)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue