Commit 2bf0ad3b authored by Theodor Thornhill's avatar Theodor Thornhill
Browse files

Add sexp navigation to js/typescript/tsx-ts-mode

* lisp/progmodes/js.el (js--treesit-sexp-nodes): Add node types.
(js-ts-mode): Set 'treesit-sexp-type-regexp'.
* lisp/progmodes/typescript-ts-mode.el
(typescript-ts-mode--sexp-nodes): Add node types.
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-base-mode): Set
'treesit-sexp-type-regexp'.
(tsx-ts-mode): Add in jsx nodes.
parent f55bbc68
Pipeline #22902 passed with stage
in 3 minutes
......@@ -3817,6 +3817,29 @@ Currently there are `js-mode' and `js-ts-mode'."
"Nodes that designate sentences in JavaScript.
See `treesit-sentence-type-regexp' for more information.")
(defvar js--treesit-sexp-nodes
'("expression"
"pattern"
"array"
"function"
"string"
"escape"
"template"
"regex"
"number"
"identifier"
"this"
"super"
"true"
"false"
"null"
"undefined"
"arguments"
"pair"
"jsx")
"Nodes that designate sexps in JavaScript.
See `treesit-sexp-type-regexp' for more information.")
;;;###autoload
(define-derived-mode js-ts-mode js-base-mode "JavaScript"
"Major mode for editing JavaScript.
......@@ -3860,6 +3883,9 @@ See `treesit-sentence-type-regexp' for more information.")
(setq-local treesit-sentence-type-regexp
(regexp-opt js--treesit-sentence-nodes))
(setq-local treesit-sexp-type-regexp
(regexp-opt js--treesit-sexp-nodes))
;; Fontification.
(setq-local treesit-font-lock-settings js--treesit-font-lock-settings)
(setq-local treesit-font-lock-feature-list
......
......@@ -338,6 +338,28 @@ Argument LANGUAGE is either `typescript' or `tsx'."
"Nodes that designate sentences in TypeScript.
See `treesit-sentence-type-regexp' for more information.")
(defvar typescript-ts-mode--sexp-nodes
'("expression"
"pattern"
"array"
"function"
"string"
"escape"
"template"
"regex"
"number"
"identifier"
"this"
"super"
"true"
"false"
"null"
"undefined"
"arguments"
"pair")
"Nodes that designate sexps in TypeScript.
See `treesit-sexp-type-regexp' for more information.")
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode))
......@@ -373,6 +395,9 @@ See `treesit-sentence-type-regexp' for more information.")
(setq-local treesit-sentence-type-regexp
(regexp-opt typescript-ts-mode--sentence-nodes))
(setq-local treesit-sexp-type-regexp
(regexp-opt typescript-ts-mode--sexp-nodes))
;; Imenu (same as in `js-ts-mode').
(setq-local treesit-simple-imenu-settings
`(("Function" "\\`function_declaration\\'" nil nil)
......@@ -438,6 +463,11 @@ See `treesit-sentence-type-regexp' for more information.")
'("jsx_element"
"jsx_self_closing_element"))))
(setq-local treesit-sexp-type-regexp
(regexp-opt (append
typescript-ts-mode--sexp-nodes
'("jsx"))))
;; Font-lock.
(setq-local treesit-font-lock-settings
(typescript-ts-mode--font-lock-settings 'tsx))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment