diff options
author | Yuan Fu <casouri@gmail.com> | 2022-11-20 16:56:33 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2022-11-20 17:04:58 -0800 |
commit | 32870d2f207536bb7932beeb2e0ec9a4e0146560 (patch) | |
tree | 7178d8a11d9b575306118a3fddbcd39e284bb359 | |
parent | 625ea08652053617034bf8ceee0d6cfae34f2dcc (diff) | |
download | emacs-32870d2f207536bb7932beeb2e0ec9a4e0146560.tar.gz emacs-32870d2f207536bb7932beeb2e0ec9a4e0146560.tar.bz2 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.el | 6 | ||||
-rw-r--r-- | lisp/progmodes/java-ts-mode.el | 10 | ||||
-rw-r--r-- | lisp/progmodes/js.el | 7 | ||||
-rw-r--r-- | lisp/progmodes/json-ts-mode.el | 2 | ||||
-rw-r--r-- | lisp/progmodes/python.el | 3 | ||||
-rw-r--r-- | lisp/textmodes/css-mode.el | 3 |
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." "Return Imenu alist for the current buffer." (let* ((node (treesit-buffer-root-node)) (func-tree (treesit-induce-sparse-tree - node "^function_definition$")) + node "^function_definition$" nil 1000)) (var-tree (treesit-induce-sparse-tree - node "^declaration$")) + node "^declaration$" nil 1000)) (struct-tree (treesit-induce-sparse-tree - node "^struct_specifier$")) + node "^struct_specifier$" nil 1000)) (func-index (c-ts-mode--imenu-1 func-tree)) (var-index (c-ts-mode--imenu-1 var-tree)) (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." (class-tree `("Class" . ,(java-ts-mode--imenu-1 (treesit-induce-sparse-tree - node "^class_declaration$")))) + node "^class_declaration$" nil 1000)))) (interface-tree `("Interface" . ,(java-ts-mode--imenu-1 (treesit-induce-sparse-tree - node "^interface_declaration$")))) + node "^interface_declaration$" nil 1000)))) (enum-tree `("Enum" . ,(java-ts-mode--imenu-1 (treesit-induce-sparse-tree - node "^enum_declaration$")))) + node "^enum_declaration$" nil 1000)))) (record-tree `("Record" . ,(java-ts-mode--imenu-1 (treesit-induce-sparse-tree - node "^record_declaration$")))) + node "^record_declaration$" nil 1000)))) (method-tree `("Method" . ,(java-ts-mode--imenu-1 (treesit-induce-sparse-tree - node "^method_declaration$"))))) + node "^method_declaration$" nil 1000))))) (cl-remove-if #'null `(,(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*\"." (let* ((node (treesit-buffer-root-node)) (class-tree (treesit-induce-sparse-tree node (rx (or "class_declaration" - "method_definition")))) + "method_definition")) + nil 1000)) (func-tree (treesit-induce-sparse-tree - node "function_declaration")) + node "function_declaration" nil 1000)) (var-tree (treesit-induce-sparse-tree - node "lexical_declaration"))) + node "lexical_declaration" nil 1000))) `(("Class" . ,(js--treesit-imenu-1 class-tree)) ("Varieable" . ,(js--treesit-imenu-1 var-tree)) ("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." "Return Imenu alist for the current buffer." (let* ((node (treesit-buffer-root-node)) (tree (treesit-induce-sparse-tree - node "pair"))) + node "pair" nil 1000))) (json-ts-mode--imenu-1 tree))) ;;;###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." (rx (seq bol (or "function" "class") "_definition" - eol))))) + eol)) + nil 1000))) (python--imenu-treesit-create-index-1 tree))) (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." "Return Imenu alist for the current buffer." (let* ((node (treesit-buffer-root-node)) (tree (treesit-induce-sparse-tree - node (rx (or "rule_set" "media_statement"))))) + node (rx (or "rule_set" "media_statement")) + nil 1000))) (css--treesit-imenu-1 tree))) ;;; Completion |