aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2022-11-20 16:56:33 -0800
committerYuan Fu2022-11-20 17:04:58 -0800
commit32870d2f207536bb7932beeb2e0ec9a4e0146560 (patch)
tree7178d8a11d9b575306118a3fddbcd39e284bb359
parent625ea08652053617034bf8ceee0d6cfae34f2dcc (diff)
downloademacs-32870d2f207536bb7932beeb2e0ec9a4e0146560.tar.gz
emacs-32870d2f207536bb7932beeb2e0ec9a4e0146560.zip
Limit recursion level for tree-sitter imenu functions
Generating imenu index doesn't require going down to the bottom of the tree (defun's are usually top-level). Add limit so we don't go too far down on very large buffers. * lisp/progmodes/c-ts-mode.el (c-ts-mode--imenu) * lisp/progmodes/java-ts-mode.el (java-ts-mode--imenu) * lisp/progmodes/js.el (js--treesit-imenu) * lisp/progmodes/json-ts-mode.el (json-ts-mode--imenu) * lisp/progmodes/python.el (python-imenu-treesit-create-index) * lisp/textmodes/css-mode.el (css--treesit-imenu): Add limit to treesit-induce-sparse-tree.
-rw-r--r--lisp/progmodes/c-ts-mode.el6
-rw-r--r--lisp/progmodes/java-ts-mode.el10
-rw-r--r--lisp/progmodes/js.el7
-rw-r--r--lisp/progmodes/json-ts-mode.el2
-rw-r--r--lisp/progmodes/python.el3
-rw-r--r--lisp/textmodes/css-mode.el3
6 files changed, 17 insertions, 14 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 9fc7e6f67c2..3b7007bfeeb 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -448,11 +448,11 @@ the subtrees."
448 "Return Imenu alist for the current buffer." 448 "Return Imenu alist for the current buffer."
449 (let* ((node (treesit-buffer-root-node)) 449 (let* ((node (treesit-buffer-root-node))
450 (func-tree (treesit-induce-sparse-tree 450 (func-tree (treesit-induce-sparse-tree
451 node "^function_definition$")) 451 node "^function_definition$" nil 1000))
452 (var-tree (treesit-induce-sparse-tree 452 (var-tree (treesit-induce-sparse-tree
453 node "^declaration$")) 453 node "^declaration$" nil 1000))
454 (struct-tree (treesit-induce-sparse-tree 454 (struct-tree (treesit-induce-sparse-tree
455 node "^struct_specifier$")) 455 node "^struct_specifier$" nil 1000))
456 (func-index (c-ts-mode--imenu-1 func-tree)) 456 (func-index (c-ts-mode--imenu-1 func-tree))
457 (var-index (c-ts-mode--imenu-1 var-tree)) 457 (var-index (c-ts-mode--imenu-1 var-tree))
458 (struct-index (c-ts-mode--imenu-1 struct-tree))) 458 (struct-index (c-ts-mode--imenu-1 struct-tree)))
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index 6a800d292c8..62962b7293b 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -246,23 +246,23 @@ the subtrees."
246 (class-tree 246 (class-tree
247 `("Class" . ,(java-ts-mode--imenu-1 247 `("Class" . ,(java-ts-mode--imenu-1
248 (treesit-induce-sparse-tree 248 (treesit-induce-sparse-tree
249 node "^class_declaration$")))) 249 node "^class_declaration$" nil 1000))))
250 (interface-tree 250 (interface-tree
251 `("Interface" . ,(java-ts-mode--imenu-1 251 `("Interface" . ,(java-ts-mode--imenu-1
252 (treesit-induce-sparse-tree 252 (treesit-induce-sparse-tree
253 node "^interface_declaration$")))) 253 node "^interface_declaration$" nil 1000))))
254 (enum-tree 254 (enum-tree
255 `("Enum" . ,(java-ts-mode--imenu-1 255 `("Enum" . ,(java-ts-mode--imenu-1
256 (treesit-induce-sparse-tree 256 (treesit-induce-sparse-tree
257 node "^enum_declaration$")))) 257 node "^enum_declaration$" nil 1000))))
258 (record-tree 258 (record-tree
259 `("Record" . ,(java-ts-mode--imenu-1 259 `("Record" . ,(java-ts-mode--imenu-1
260 (treesit-induce-sparse-tree 260 (treesit-induce-sparse-tree
261 node "^record_declaration$")))) 261 node "^record_declaration$" nil 1000))))
262 (method-tree 262 (method-tree
263 `("Method" . ,(java-ts-mode--imenu-1 263 `("Method" . ,(java-ts-mode--imenu-1
264 (treesit-induce-sparse-tree 264 (treesit-induce-sparse-tree
265 node "^method_declaration$"))))) 265 node "^method_declaration$" nil 1000)))))
266 (cl-remove-if 266 (cl-remove-if
267 #'null 267 #'null
268 `(,(when (cdr class-tree) class-tree) 268 `(,(when (cdr class-tree) class-tree)
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 4b07c0d12c8..50674a1c039 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3688,11 +3688,12 @@ definition*\"."
3688 (let* ((node (treesit-buffer-root-node)) 3688 (let* ((node (treesit-buffer-root-node))
3689 (class-tree (treesit-induce-sparse-tree 3689 (class-tree (treesit-induce-sparse-tree
3690 node (rx (or "class_declaration" 3690 node (rx (or "class_declaration"
3691 "method_definition")))) 3691 "method_definition"))
3692 nil 1000))
3692 (func-tree (treesit-induce-sparse-tree 3693 (func-tree (treesit-induce-sparse-tree
3693 node "function_declaration")) 3694 node "function_declaration" nil 1000))
3694 (var-tree (treesit-induce-sparse-tree 3695 (var-tree (treesit-induce-sparse-tree
3695 node "lexical_declaration"))) 3696 node "lexical_declaration" nil 1000)))
3696 `(("Class" . ,(js--treesit-imenu-1 class-tree)) 3697 `(("Class" . ,(js--treesit-imenu-1 class-tree))
3697 ("Varieable" . ,(js--treesit-imenu-1 var-tree)) 3698 ("Varieable" . ,(js--treesit-imenu-1 var-tree))
3698 ("Function" . ,(js--treesit-imenu-1 func-tree))))) 3699 ("Function" . ,(js--treesit-imenu-1 func-tree)))))
diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el
index 7e0dd179114..c03ff851504 100644
--- a/lisp/progmodes/json-ts-mode.el
+++ b/lisp/progmodes/json-ts-mode.el
@@ -115,7 +115,7 @@ the subtrees."
115 "Return Imenu alist for the current buffer." 115 "Return Imenu alist for the current buffer."
116 (let* ((node (treesit-buffer-root-node)) 116 (let* ((node (treesit-buffer-root-node))
117 (tree (treesit-induce-sparse-tree 117 (tree (treesit-induce-sparse-tree
118 node "pair"))) 118 node "pair" nil 1000)))
119 (json-ts-mode--imenu-1 tree))) 119 (json-ts-mode--imenu-1 tree)))
120 120
121;;;###autoload 121;;;###autoload
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 2f967ebab24..c49af223c66 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5492,7 +5492,8 @@ Similar to `python-imenu-create-index' but use tree-sitter."
5492 (rx (seq bol 5492 (rx (seq bol
5493 (or "function" "class") 5493 (or "function" "class")
5494 "_definition" 5494 "_definition"
5495 eol))))) 5495 eol))
5496 nil 1000)))
5496 (python--imenu-treesit-create-index-1 tree))) 5497 (python--imenu-treesit-create-index-1 tree)))
5497 5498
5498(defun python-imenu-treesit-create-flat-index () 5499(defun python-imenu-treesit-create-flat-index ()
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 6915e499bba..97272cb7147 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1406,7 +1406,8 @@ the subtrees."
1406 "Return Imenu alist for the current buffer." 1406 "Return Imenu alist for the current buffer."
1407 (let* ((node (treesit-buffer-root-node)) 1407 (let* ((node (treesit-buffer-root-node))
1408 (tree (treesit-induce-sparse-tree 1408 (tree (treesit-induce-sparse-tree
1409 node (rx (or "rule_set" "media_statement"))))) 1409 node (rx (or "rule_set" "media_statement"))
1410 nil 1000)))
1410 (css--treesit-imenu-1 tree))) 1411 (css--treesit-imenu-1 tree)))
1411 1412
1412;;; Completion 1413;;; Completion