aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorYuan Fu2022-12-27 17:02:03 -0800
committerYuan Fu2022-12-27 17:41:43 -0800
commitba1ddea9dabf51c9c6e463d667bcce0b48294453 (patch)
tree5553592930b6e4482b351090e6a3adaca134c0d1 /test/src
parent7512b9025a152ea953918e1c0748b695b742b4b6 (diff)
downloademacs-ba1ddea9dabf51c9c6e463d667bcce0b48294453.tar.gz
emacs-ba1ddea9dabf51c9c6e463d667bcce0b48294453.zip
Fix treesit--things-around (bug#60355)
Current implementation of treesit--things-around only searches forward for REGEXP and go up the tree until it finds a valid thing, if nothing matches it gives up. This makes it sometimes miss defuns. The new implementation tries multiple times (of search forward + go up) until it exhausts all possible defun nodes. * lisp/treesit.el (treesit--things-around): New implementation. (treesit--navigate-defun): Refactor to use treesit-node-top-level to simplify code, and add some guards in the predicate function. * test/src/treesit-tests.el: (treesit--ert-defun-navigation-elixir-program): New variable. (treesit-defun-navigation-nested-4): New test.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/treesit-tests.el40
1 files changed, 39 insertions, 1 deletions
diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el
index b0fbed4b06c..ec686c69642 100644
--- a/test/src/treesit-tests.el
+++ b/test/src/treesit-tests.el
@@ -940,7 +940,28 @@ and \"]\"."
940[999]} 940[999]}
941[110] 941[110]
942" 942"
943 "Javascript source for navigation test.") 943 "Bash source for navigation test.")
944
945(defvar treesit--ert-defun-navigation-elixir-program
946 "[100]
947[101]def bar() do
948[999]end
949[102]
950[103]defmodule Example do[0]
951[999] @impl true
952[104] [1]def bar() do[2]
953[999] end[3]
954[105] [4]
955[106] [5]def baz() do[6]
956[999] end[7]
957[107] [8]
958[999]end[9]
959[108]
960[109]def bar() do
961[999]end
962[110]
963"
964 "Elixir source for navigation test.")
944 965
945(defvar treesit--ert-defun-navigation-nested-master 966(defvar treesit--ert-defun-navigation-nested-master
946 ;; START PREV-BEG NEXT-END PREV-END NEXT-BEG 967 ;; START PREV-BEG NEXT-END PREV-END NEXT-BEG
@@ -1022,6 +1043,23 @@ the prev-beg, now point should be at marker 103\", etc.")
1022 treesit--ert-defun-navigation-bash-program 1043 treesit--ert-defun-navigation-bash-program
1023 treesit--ert-defun-navigation-nested-master))) 1044 treesit--ert-defun-navigation-nested-master)))
1024 1045
1046(ert-deftest treesit-defun-navigation-nested-4 ()
1047 "Test defun navigation using Elixir.
1048This tests bug#60355."
1049 (skip-unless (treesit-language-available-p 'bash))
1050 ;; Nested defun navigation
1051 (let ((treesit-defun-tactic 'nested)
1052 (pred (lambda (node)
1053 (member (treesit-node-text
1054 (treesit-node-child-by-field-name node "target"))
1055 '("def" "defmodule")))))
1056 (treesit--ert-test-defun-navigation
1057 (lambda ()
1058 (treesit-parser-create 'elixir)
1059 (setq-local treesit-defun-type-regexp `("call" . ,pred)))
1060 treesit--ert-defun-navigation-elixir-program
1061 treesit--ert-defun-navigation-nested-master)))
1062
1025(ert-deftest treesit-defun-navigation-top-level () 1063(ert-deftest treesit-defun-navigation-top-level ()
1026 "Test top-level only defun navigation." 1064 "Test top-level only defun navigation."
1027 (skip-unless (treesit-language-available-p 'python)) 1065 (skip-unless (treesit-language-available-p 'python))