summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2025-03-29 21:15:02 -0700
committerYuan Fu <casouri@gmail.com>2025-03-29 21:18:24 -0700
commit651418895d507001f161e2e22ca9b85647bca19b (patch)
tree3b9a6d9cee413321c5344b14d3b04a639a3ea3b7
parente1b15d58b508da279162c585b6b3783f9e267427 (diff)
downloademacs-651418895d507001f161e2e22ca9b85647bca19b.tar.gz
emacs-651418895d507001f161e2e22ca9b85647bca19b.tar.bz2
emacs-651418895d507001f161e2e22ca9b85647bca19b.zip
Tighten the criteria for a defun in typescript-ts-mode (bug#77369)
* lisp/progmodes/typescript-ts-mode.el: (typescript-ts-mode--defun-predicate): New function. (typescript-ts-base-mode): Use new predicate.
-rw-r--r--lisp/progmodes/typescript-ts-mode.el15
1 files changed, 14 insertions, 1 deletions
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 9051a841887..bc4b635735f 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -523,6 +523,17 @@ See `treesit-thing-settings' for more information.")
eos)
"Settings for `treesit-defun-type-regexp'.")
+(defun typescript-ts-mode--defun-predicate (node)
+ "Check if NODE is a defun."
+ (pcase (treesit-node-type node)
+ ("lexical_declaration"
+ (treesit-node-match-p
+ (treesit-node-child-by-field-name
+ (treesit-node-child node 0 'named)
+ "value")
+ "arrow_function"))
+ (_ t)))
+
(defun typescript-ts-mode--defun-name (node)
"Return the defun name of NODE.
Return nil if there is no name or if NODE is not a defun node."
@@ -573,7 +584,9 @@ This mode is intended to be inherited by concrete major modes."
(setq-local electric-layout-rules
'((?\; . after) (?\{ . after) (?\} . before)))
;; Navigation.
- (setq-local treesit-defun-type-regexp typescript-ts-mode--defun-type-regexp)
+ (setq-local treesit-defun-type-regexp
+ (cons typescript-ts-mode--defun-type-regexp
+ #'typescript-ts-mode--defun-predicate))
(setq-local treesit-defun-name-function #'typescript-ts-mode--defun-name)
(setq-local treesit-thing-settings