summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/js.el57
-rw-r--r--lisp/textmodes/mhtml-ts-mode.el12
-rw-r--r--lisp/textmodes/yaml-ts-mode.el2
3 files changed, 41 insertions, 30 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 1142786ffaa..e5dae4eed5f 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3544,6 +3544,9 @@ Check if a node type is available, then return the right indent rules."
:feature 'definition
`(,@(js--treesit-font-lock-compatibility-definition-feature)
+ (class
+ name: (identifier) @font-lock-type-face)
+
(class_declaration
name: (identifier) @font-lock-type-face)
@@ -3708,7 +3711,7 @@ Return nil if there is no name or if NODE is not a defun node."
(treesit-node-text
(treesit-node-child-by-field-name
(pcase (treesit-node-type node)
- ("lexical_declaration"
+ ((or "lexical_declaration" "variable_declaration")
(treesit-search-subtree node "variable_declarator" nil nil 1))
((or "function_declaration" "method_definition" "class_declaration")
node))
@@ -3716,9 +3719,15 @@ Return nil if there is no name or if NODE is not a defun node."
t))
(defun js--treesit-valid-imenu-entry (node)
- "Return nil if NODE is a non-top-level \"lexical_declaration\"."
+ "Return nil if NODE is a non-top-level lexical/variable declaration."
(pcase (treesit-node-type node)
- ("lexical_declaration" (treesit-node-top-level node))
+ ((or "lexical_declaration" "variable_declaration")
+ (not (treesit-node-top-level
+ node (rx bos (or "class_declaration"
+ "method_definition"
+ "function_declaration"
+ "function_expression")
+ eos))))
(_ t)))
(defun js--treesit-language-at-point (point)
@@ -3857,8 +3866,7 @@ Currently there are `js-mode' and `js-ts-mode'."
"labeled_statement"
"variable_declaration"
"lexical_declaration"
- "jsx_element"
- "jsx_self_closing_element")
+ "jsx_attribute")
"Nodes that designate sentences in JavaScript.
See `treesit-thing-settings' for more information.")
@@ -3906,8 +3914,9 @@ See `treesit-thing-settings' for more information.")
"object_pattern"
"array"
"array_pattern"
+ "jsx_element"
"jsx_expression"
- "_jsx_string"
+ "jsx_self_closing_element"
"string"
"regex"
"arguments"
@@ -3938,24 +3947,34 @@ See `treesit-thing-settings' for more information.")
"Settings for `treesit-font-lock-feature-list'.")
(defvar js--treesit-simple-imenu-settings
- `(("Function" "\\`function_declaration\\'" nil nil)
- ("Variable" "\\`lexical_declaration\\'"
- js--treesit-valid-imenu-entry nil)
- ("Class" ,(rx bos (or "class_declaration"
- "method_definition")
- eos)
- nil nil))
+ `(("Class" "\\`class_declaration\\'" nil nil)
+ ("Method" "\\`method_definition\\'" nil nil)
+ ("Function" "\\`function_declaration\\'" nil nil)
+ ("Variable" ,(rx bos (or "lexical_declaration"
+ "variable_declaration")
+ eos)
+ ,#'js--treesit-valid-imenu-entry nil))
"Settings for `treesit-simple-imenu'.")
+(defvar js-ts-mode--outline-predicate
+ `(or (and "\\`class\\'" named)
+ ,(rx bos (or"class_declaration"
+ "method_definition"
+ "function_declaration"
+ "function_expression")
+ eos)))
+
(defvar js--treesit-defun-type-regexp
- (rx (or "class_declaration"
- "method_definition"
- "function_declaration"
- "lexical_declaration"))
+ (rx bos (or "class_declaration"
+ "method_definition"
+ "function_declaration"
+ "lexical_declaration"
+ "variable_declaration")
+ eos)
"Settings for `treesit-defun-type-regexp'.")
(defvar js--treesit-jsdoc-comment-regexp
- (rx (or "comment" "line_comment" "block_comment" "description"))
+ (rx bos (or "comment" "line_comment" "block_comment" "description") eos)
"Regexp for `c-ts-common--comment-regexp'.")
;;;###autoload
@@ -4011,6 +4030,8 @@ See `treesit-thing-settings' for more information.")
;; Imenu
(setq-local treesit-simple-imenu-settings js--treesit-simple-imenu-settings)
+ ;; Outline minor mode
+ (setq-local treesit-outline-predicate js-ts-mode--outline-predicate)
(treesit-major-mode-setup)
diff --git a/lisp/textmodes/mhtml-ts-mode.el b/lisp/textmodes/mhtml-ts-mode.el
index 4d538514f1c..5c4f90cd193 100644
--- a/lisp/textmodes/mhtml-ts-mode.el
+++ b/lisp/textmodes/mhtml-ts-mode.el
@@ -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)
diff --git a/lisp/textmodes/yaml-ts-mode.el b/lisp/textmodes/yaml-ts-mode.el
index 9b211902e14..7d11223aefa 100644
--- a/lisp/textmodes/yaml-ts-mode.el
+++ b/lisp/textmodes/yaml-ts-mode.el
@@ -154,7 +154,7 @@ Return nil if there is no name or if NODE is not a defun node."
"Limit outlines to top-level mappings."
(let ((regexp (rx (or "block_mapping_pair" "block_sequence_item"))))
(when (string-match-p regexp (treesit-node-type node))
- (not (treesit-parent-until node regexp)))))
+ (not (treesit-node-top-level node regexp)))))
;;;###autoload
(define-derived-mode yaml-ts-mode text-mode "YAML"