aboutsummaryrefslogtreecommitdiffstats
path: root/test/src/treesit-tests.el (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Merge from origin/emacs-29Eli Zaretskii2024-02-101-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 7d3a1444864 ; Mention defface's and their :version tags in CONTRIBUTE. 09c53b717d4 * admin/notes/kind-communication: New file. 31ca4e5501f ; And another fix of CONTRIBUTE. d65499e7908 ; Another clarification in CONTRIBUTE. 571ec583d64 ; Clarify "ChangeLog entries" in CONTRIBUTE. e2682316867 Don't skip links to "." and ".." in Dired when marking files e25d11314d8 Pass unquoted filename to user-supplied MUSTMATCH predicate 47496993703 * doc/lispref/parsing.texi (Retrieving Nodes): Improve do... d0673ea0d42 ; * etc/PROBLEMS: Workaround for Windows key "stuck" (bug... * lisp/emacs-lisp/trace.el: * java/org/gnu/emacs/EmacsWindow.java (onDragEvent): Remove training whitespace.
| * * doc/lispref/parsing.texi (Retrieving Nodes): Improve documentation.Juri Linkov2024-02-041-1/+1
| | | | | | | | | | Update optional arguments 'predicate' and 'include-node' of 'treesit-node-top-level'.
* | Merge from savannah/emacs-29Po Lu2024-01-021-1/+1
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dc4e6b13296 ; Update copyright years in more files 64b37776318 ; Run set-copyright from admin.el 8e1c56ae467 ; Add 2024 to copyright years # Conflicts: # doc/misc/modus-themes.org # doc/misc/texinfo.tex # etc/NEWS # etc/refcards/ru-refcard.tex # etc/themes/modus-operandi-theme.el # etc/themes/modus-themes.el # etc/themes/modus-vivendi-theme.el # lib/alloca.in.h # lib/binary-io.h # lib/c-ctype.h # lib/c-strcasecmp.c # lib/c-strncasecmp.c # lib/careadlinkat.c # lib/cloexec.c # lib/close-stream.c # lib/diffseq.h # lib/dup2.c # lib/filemode.h # lib/fpending.c # lib/fpending.h # lib/fsusage.c # lib/getgroups.c # lib/getloadavg.c # lib/gettext.h # lib/gettime.c # lib/gettimeofday.c # lib/group-member.c # lib/malloc.c # lib/md5-stream.c # lib/md5.c # lib/md5.h # lib/memmem.c # lib/memrchr.c # lib/nanosleep.c # lib/save-cwd.h # lib/sha1.c # lib/sig2str.c # lib/stdlib.in.h # lib/strtoimax.c # lib/strtol.c # lib/strtoll.c # lib/time_r.c # lib/xalloc-oversized.h # lisp/auth-source-pass.el # lisp/emacs-lisp/lisp-mnt.el # lisp/emacs-lisp/timer.el # lisp/info-look.el # lisp/jit-lock.el # lisp/loadhist.el # lisp/mail/rmail.el # lisp/net/ntlm.el # lisp/net/webjump.el # lisp/progmodes/asm-mode.el # lisp/progmodes/project.el # lisp/progmodes/sh-script.el # lisp/textmodes/flyspell.el # lisp/textmodes/reftex-toc.el # lisp/textmodes/reftex.el # lisp/textmodes/tex-mode.el # lisp/url/url-gw.el # m4/alloca.m4 # m4/clock_time.m4 # m4/d-type.m4 # m4/dirent_h.m4 # m4/dup2.m4 # m4/euidaccess.m4 # m4/fchmodat.m4 # m4/filemode.m4 # m4/fsusage.m4 # m4/getgroups.m4 # m4/getloadavg.m4 # m4/getrandom.m4 # m4/gettime.m4 # m4/gettimeofday.m4 # m4/gnulib-common.m4 # m4/group-member.m4 # m4/inttypes.m4 # m4/malloc.m4 # m4/manywarnings.m4 # m4/mempcpy.m4 # m4/memrchr.m4 # m4/mkostemp.m4 # m4/mktime.m4 # m4/nproc.m4 # m4/nstrftime.m4 # m4/pathmax.m4 # m4/pipe2.m4 # m4/pselect.m4 # m4/pthread_sigmask.m4 # m4/readlink.m4 # m4/realloc.m4 # m4/sig2str.m4 # m4/ssize_t.m4 # m4/stat-time.m4 # m4/stddef_h.m4 # m4/stdint.m4 # m4/stdio_h.m4 # m4/stdlib_h.m4 # m4/stpcpy.m4 # m4/strnlen.m4 # m4/strtoimax.m4 # m4/strtoll.m4 # m4/time_h.m4 # m4/timegm.m4 # m4/timer_time.m4 # m4/timespec.m4 # m4/unistd_h.m4 # m4/warnings.m4 # nt/configure.bat # nt/preprep.c # test/lisp/register-tests.el
| * ; Add 2024 to copyright yearsPo Lu2024-01-021-1/+1
| |
* | Merge from origin/emacs-29Eli Zaretskii2023-12-231-0/+36
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | a4751657389 * doc/man/emacsclient.1: Fix --tramp option. 1e5357d3d1f * doc/man/emacsclient.1: Add missing sections (bug#66598) fba7b9db397 Add explanation for extra parentheses in ELisp Introduction 77232826821 Add sample code to the "let*" section in "forward-paragraph" 7a00ca92c19 Fix treesit test (bug#67117) d220893216c Fix c++-ts-mode indentation (bug#67975) d386a8aa43f Recommend customizing eglot for python-base-mode bd0c7589715 Improve documentation of new native-compilation commands 1ad126c0f28 ; Fix typo 77678244b83 doc/lispintro: Don't mention `set` (bug#67734) cb3684e9dfa Fix script for some characters 2922d683b78 ; * src/treesit.c (treesit_traverse_child_helper): Fix co... 7b315e8a5c9 Fix an issue when searching subtree backward (bug#67117) 03625c2fefa Fix passive mode for tnftp client in ange-ftp.el. b6429b1c1c7 ; Improve documentation of ispell.el's dictionary database 75cc1593412 ; * etc/PROBLEMS: Update the "GnuPG hangs" entry. 67d9af1c074 Fix using disabled command without a docstring f68f3500236 Improve documentation of text properties handling when ya... 06c399914fa Eglot: Add Uiua language server
| * Fix treesit test (bug#67117)Denis Zubarev2023-12-221-7/+13
| | | | | | | | | | | | * test/src/treesit-tests.el (treesit-search-subtree-forward-1): (treesit-search-subtree-backward-1): Replace treesit--thing-at with treesit-query-capture (treesit--thing-at isn't available in Emacs 29).
| * Fix an issue when searching subtree backward (bug#67117)Denis Zubarev2023-12-181-0/+30
| | | | | | | | | | | | | | | | | | | | | | * src/treesit.c (treesit_traverse_child_helper): Do not call treesit_traverse_sibling_helper when the named node is required and the last child is the named node. Otherwise treesit_traverse_sibling_helper will move cursor to the previous sibling and last node will be skipped. * test/src/treesit-tests.el (treesit-search-subtree-forward-1): (treesit-search-subtree-backward-1): Add tests.
* | Add treesit-node-enclosed-pYuan Fu2023-11-091-0/+7
| | | | | | | | | | | | | | | | * doc/lispref/parsing.texi (Accessing Node Information): Add manual entry. * lisp/treesit.el (treesit-node-enclosed-p): New function. (treesit): Add shortdoc entry. * test/src/treesit-tests.el (treesit-node-api): Add tests.
* | Offset ranges before applying embedded tree-sitter parserDanny Freeman2023-09-171-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This feature would allow treesitter major modes to easily specify offsets when using embeded parsers. A potential use case for this is javascript template strings, when we want to apply a different parser to the string's contents, but do not want to include the template string's delimiters. * lisp/treesit.el (treesit-query-range): Accept an optional offest arg, apply the offset to all returned ranges. (treesit-range-rules): Accept an optional :offset keyword arg to adjust ranges an embded parser is applied to. (treesit-update-ranges): Forward optional :offset setting from `treesit-range-rules' to `treesit-query-rang'. * test/lisp/treesit-tests.el (treesit-range-offset): Tests the new offset functionality.
* | ; Silence byte-compilerStefan Kangas2023-08-061-0/+1
| | | | | | | | * test/src/treesit-tests.el (treesit-pattern-expand): Declare.
* | ; * src/treesit.c (treesit_query_string_string): fix last changeMattias Engdegård2023-06-171-2/+2
| | | | | | | | Escape the backslash character itself.
* | Merge from origin/emacs-29Eli Zaretskii2023-06-171-2/+2
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 84d2da003e1 ; Fix example in the Flymake manual 0a1459f1d9b * doc/misc/calc.texi (Advanced Math Functions): Correct c... 92faf1f5645 Consider 'dired-kill-when-opening-new-dired-buffer' in mo... bafe71a69fc ; Fix use-package.texi markup 018e4ca6c5d ; * doc/misc/calc.texi (Advanced Math Functions): Fix las... 1952dbd4c5f Fix Gamma function definition in calc.texi f73f82d7e89 Fix subscripts in the Calc manual 70fc7c41ef3 Improve documentation of 'declare' forms c8357582389 ; * src/lread.c (bytecode_from_rev_list): Avoid C++ comment. 28478574961 Improve tree-sitter docs 0e9307eb2b8 Fix some Texinfo markup in manuals 8dc08333eea Fix bol/bos anchors in tree-sitter :match regexps 8225ade6151 ; * src/xdisp.c (syms_of_xdisp) <display-line-numbers>: F... 1f0527a312a ; Fix last change in tex-mode.el 4da479920e6 * lisp/subr.el (with-restriction): Tweak indent rule 36aa9bd8183 ; Fix previous change aaeaf608d89 Fix setting region in the minibuffer 1383efe01d0 Fix setting $DBUS_SESSION_BUS_ADDRESS after Emacs has sta... bdb0bc2b4e4 Fix tex-mode display-buffer issues 90047c38ce9 Add test for when 'completion-auto-help' is 'visible' 2c623e4feb9 Avoid errors in 'apropos-documentation' after 'eval-buffer' dd3b98121cc ; * doc/emacs/indent.texi (Indentation Commands): Fix las... 904edf1f076 Mention indent-rigidly in the Emacs manual
| * Fix bol/bos anchors in tree-sitter :match regexpsBasil L. Contovounesios2023-06-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Further regexp fixes to follow separately (bug#64019#29). * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): * lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode--font-lock-settings): * lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings): * lisp/progmodes/js.el (js--treesit-font-lock-settings): * lisp/progmodes/python.el (python--treesit-settings): * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--font-lock-settings): * lisp/progmodes/sh-script.el (sh-mode--treesit-settings): * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode--font-lock-settings): * test/src/treesit-tests.el (treesit-query-api): Anchor :match regexps at beginning/end of string, not line.
* | Correct conversion of strings to tree-sitter query syntaxMattias Engdegård2023-06-161-1/+6
| | | | | | | | | | | | | | | | | | The treesitter query syntax for string literals differs from that of Elisp so we cannot just use the Lisp printer (bug#64017). * src/treesit.c (treesit_query_string_string): New function. (Ftreesit_pattern_expand): Use it. * test/src/treesit-tests.el (treesit-query-api): Add test case.
* | Merge from origin/emacs-29Eli Zaretskii2023-05-261-1/+1
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 6f6071c5261 Avoid duplicate load-path entry when generating package a... 117b29c6f66 ; Improve documentation of Isearch command properties a347b26cba2 Disable loading SQLite3 extensions when SQLite3 version i... fe22bf503fb ; * lisp/progmodes/project.el (project-switch-use-entire-... 64dbbde3b77 Fix visiting HTML files encoded in iso-2022 variants 5c95239aca2 ; Fix markup of some treesit vars in Elisp manual. 6ad041939be Support 'isearch-allow-scroll' in 'pixel-scroll-precision... ecccdc07a09 shr: allow moving between adjacent anchors 504ef25ef36 ; * etc/NEWS: Fix typos. d6fb868cdd3 Fix multihop file name expansion in Tramp dd3e4e14fdc Remove obsolete information from Gnus manual 2a5c946f879 Preserve mark in comint-history-isearch 6b60c8142ea Fix systemd unit completion for old versions of systemd 8c56557cd9d Fix Skeletons menu-bar menu in Python modes 58eb38cfb47 ; * etc/NEWS: missing definite article cf403628692 ; * etc/NEWS: PGTK cannot switch to -new automatically (b... ead3a2abbfc Fix loading SQLite extensions a6bddd17658 ; * etc/NEWS: Fix typos. f49fe936abd * etc/NEWS: Note dotimes loop variable scoping change (bu... cec9333dc52 Fix c-ts-mode--top-level-declarator f571e8f1bb6 Improve c-ts-mode font-lock for function names (bug#63390) 42a28ffdc27 * lisp/tab-bar.el: Don't use 'minibuffer-selected-window'... 8e61d23f71e Split windows horizontally in places that use split to cr... 459d08c7fe7 Fix tree-sitter test (bug#63481) 3bc5efb87e5 ; * lisp/emacs-lisp/benchmark.el (benchmark-progn): Fix d... # Conflicts: # etc/NEWS
| * Fix tree-sitter test (bug#63481)Yuan Fu2023-05-181-1/+1
| | | | | | | | | | | | | | | | * test/src/treesit-tests.el (treesit-basic-parsing): Latest json parser doesn't return an error on empty buffer or multiple objects anymore [1]. https://github.com/tree-sitter/tree-sitter-json/commit/40a81c01a40ac48744e0c8ccabbaba1920441199
* | ; * test/src/treesit-tests.el: declare functions to silence warningsMattias Engdegård2023-05-091-0/+3
| |
* | Make use of the new pred shapes in treesit.elYuan Fu2023-04-141-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | treesit-search-forward and friends now accept more shapes for PRED, make use of it in navigation functions. * lisp/treesit.el (treesit-node-top-level): Use treesit-node-match-p. (treesit--thing-unpack-pattern): Remove function. (treesit-beginning-of-thing) (treesit-end-of-thing): Remove PRED argument. (treesit--things-around): Remove PRED argument, use treesit-node-match-p. (treesit--top-level-thing): Remove function. (treesit--navigate-thing): Remove PRED argument. (treesit-thing-at-point): Update docstring, don't unpack PATTERN. * test/src/treesit-tests.el: (treesit--ert-test-defun-navigation): Don't unpack pattern.
* | Fix tree-sitter testYuan Fu2023-04-131-3/+3
| | | | | | | | | | * test/src/treesit-tests.el: (treesit-search-forward-predicate-invalid-predicate): Fix test.
* | Fix previous commit on tree-sitterYuan Fu2023-04-131-4/+5
| | | | | | | | | | | | | | | | | | | | * src/treesit.c: (treesit_traverse_validate_predicate): Don't accept symbols. (treesit_traverse_match_predicate): Don't accept symbols, and use correct variable for the regexp and pred check. * test/src/treesit-tests.el: (treesit-search-forward-predicate): Fix the test.
* | Support more predicates in tree-sitter search functionsYuan Fu2023-04-131-0/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now we support regexp strings and predicate functions for the PRED argument. This change adds support for (not ...) (or ...) and (regexp . pred) predicates. I still need to find a place to document the supported shapes of a predicate. * src/treesit.c (treesit_traverse_validate_predicate): New function. (treesit_traverse_match_predicate): Support more predicate shapes. (treesit_search_dfs): (treesit_search_forward) (treesit_build_sparse_tree): Fix docstring (unrelated to this change). (Ftreesit_search_subtree) (Ftreesit_search_forward) (Ftreesit_induce_sparse_tree): Use the new function to validate predicate shape. (syms_of_treesit): New error Qtreesit_invalid_predicate. * test/src/treesit-tests.el: (treesit--ert-search-setup): Add edebug declaration. (treesit-search-forward-predicate) (treesit-search-forward-predicate-invalid-predicate): New tests.
* | Fix tree-sitter testsYuan Fu2023-04-131-30/+32
|/ | | | | | | | | | | | | | After 2ce27563ecc, treesit--navigate-things takes a TACTIC argument instead of using treesit-defun-tactic, so the tests need to change from binding treesit-defun-tactic to passing the tactic argument, which is what this change does. * test/src/treesit-tests.el: (treesit--ert-insert-and-parse-marker): New argument TACTIC. (treesit-defun-navigation-nested-1) (treesit-defun-navigation-nested-2) (treesit-defun-navigation-nested-3) (treesit-defun-navigation-top-level): Pass TACTIC argument.
* Adjust tree-sitter defun navigation (bug#61617)Yuan Fu2023-02-271-16/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change, when you use a tree-sitter navigation function to move to the next beginning of a thing, it jumps over the immediate next thing and lands you at the beginning of the next-next thing. Eg, when point is at the "|", and we evaluate (treesit--navigate-thing pos 1 'beg), we go from | (thing) (thing) to (thing) |(thing) But some might expect point to go to |(thing) (thing) instead, which makes sense. Also, that's how Emacs expect defun navigation functions to work. The discrepancy in expectation causes bug#61617. In this change I made tree-sitter navigation functions to work as what Emacs expects. And what I described for moving to the next beginning of thing is similarly applicable to moving to the end of previous end of thing. * lisp/treesit.el (treesit-beginning-of-defun) (treesit-end-of-defun): Handle the case where defun-skipper moves point back to where we started, by adding a retry. (treesit--navigate-thing): Add a single condition checking for progress to the condition form responsible for checking whether to skip the next defun. Namely (eq pos (funcall advance next)))). * test/src/treesit-tests.el: (treesit--ert-defun-navigation-nested-master) (treesit--ert-defun-navigation-top-level-master): Change tests to reflect the new expectation.
* Add 'live' property to treesit-node-check (bug#61235)Yuan Fu2023-02-091-1/+13
| | | | | | | * doc/lispref/parsing.texi (Accessing Node Information): Document. * src/treesit.c (treesit_parser_live_p): New function. (Ftreesit_node_check): Add 'live' property. * test/src/treesit-tests.el (treesit-node-api): Add tests.
* ; Add 2023 to copyright years.Eli Zaretskii2023-01-011-1/+1
|
* Fix tree-sitter typosYuan Fu2022-12-281-1/+1
| | | | | | | * doc/lispref/parsing.texi (Tree-sitter major modes): * lisp/progmodes/java-ts-mode.el: * test/src/treesit-tests.el (treesit-defun-navigation-nested-4): Fix typo.
* Fix treesit--things-around (bug#60355)Yuan Fu2022-12-271-1/+39
| | | | | | | | | | | | | | | 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.
* ; * test/src/treesit-tests.el: remove dead store (bytecomp warning)Mattias Engdegård2022-12-271-3/+1
|
* Add a new tree-sitter query predicate 'pred'Yuan Fu2022-12-261-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I realized that using an arbitrary function as the predicate in queries is very helpful for some queries I'm writing for python and javascript, and presumably most other languages[1]. Granted, we can already filter out unwanted nodes by using a function instead of a face for the capture name, and (1) determine whether the captured node is valid and (2) fontify that node if it's valid. However, such approach is a bit more cumbersome and more importantly gets in the way of another potential use of the fontification queries: context extraction. For example, I could use the query for the 'variable' feature to get all the variables in a certain region. In this use-case, we want the filtering happen before returning the captured nodes. Besides, the change is relatively small and straightforward: most code are already there, I just need to add some boilerplate. [1] For a code like aa.bb(cc), we want bb to be in function face, because obviously its a function. But for aa.bb, we want bb to be in property face, because it's a property. In the AST, bb is always a property, the difference between the two cases is the enclosing node: in the first case, aa.bb is in a "call_expression" node, indicating that bb is used as a function (a method). So we want a predicate function that checks whether bb is used as a function or a property, and determine whether it should be in function or property face. * doc/lispref/parsing.texi (Pattern Matching): Update manual. * src/treesit.c (Ftreesit_pattern_expand): Handle :pred. (treesit_predicate_capture_name_to_node): A new function extracted from treesit_predicate_capture_name_to_text. (treesit_predicate_capture_name_to_text): Use the newly extracted function. (treesit_predicate_pred): New predicate function. (treesit_eval_predicates): Add new predicate. Also fix a bug: we want to AND the results of each predicate. * test/src/treesit-tests.el (treesit--ert-pred-last-sibling): New helper function. (treesit-query-api): Test #pred predicate.
* ; Fix tree-sitter defun testsYuan Fu2022-12-261-30/+34
| | | | | * test/src/treesit-tests.el (treesit--ert-test-defun-navigation): Change treesit--navigate-defun to treesit--navigate-thing.
* Switch to use cursor API in treesit.cYuan Fu2022-12-171-0/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | ts_node_parent has bugs (bug#60054), using cursor API avoids that. Tree-sitter's author might remove ts_node_parent in the future, so might as well switch to use cursors now. We are basically reimplementing some of the logic of ts_node_prev_sibling and ts_node_parent in the sibling helper and cursor helper functions. See also https://github.com/tree-sitter/tree-sitter/issues/1992 * src/treesit.c (treesit_traverse_sibling_helper) (treesit_traverse_child_helper) (treesit_traverse_match_predicate): Reimplemented to use the cursor API. (treesit_search_dfs) (treesit_search_forward): Use the new cursor helper functions. (Ftreesit_search_subtree) (Ftreesit_search_forward) (Ftreesit_induce_sparse_tree): Use cursors. * test/src/treesit-tests.el (treesit-search-subtree): New test. (treesit--ert-search-setup): New macro. (treesit-search-forward) (treesit-search-forward-named-only) (treesit-search-backward) (treesit-search-backward-named-only) (treesit-cursor-helper-with-missing-node): New tests.
* ; Fix typosStefan Kangas2022-12-131-3/+3
|
* Add improved tree-sitter navigationYuan Fu2022-12-121-0/+282
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new set of functions (and tests) should eliminate defun-navigation bugs and limitations we currently have. This commit doesn't change any existing bahavior: treesit-beginning/end-of-defun and friends are unchanged. The plan is to later switch gear and replace the current functions with the new ones introduced in this change. This is a relatively big change, but I've setup a comprehensive test, and it should fix current bugs, so I think it's ok to put it on the release branch. The gist of the new navigation is to use treesit--defuns-around to find the previous sibling defun, next sibling defun, and the parent defun, then use this information to move to previous/next beginning/end of defun in treesit--navigate-defun. I also added comprehensive testing that tests all four possible operations (prev-beg, next-beg, prev-end, next-end) starting at all possible positions (between two sibling defuns, inside a sibling defun, etc). * lisp/treesit.el (treesit-defun-type-regexp): Expand definition to allow (REGEXP . FILTER). Old functions don't support this, but it should be fine since we are soon replacing them. (treesit-defun-tactic) (treesit-defun-skipper): New variables. (treesit-default-defun-skipper) (treesit--defuns-around) (treesit--top-level-defun) (treesit--navigate-defun): New functions. * test/src/treesit-tests.el (treesit--ert-insert-and-parse-marker) (treesit--ert-collect-positions) (treesit--ert-test-defun-navigation): New helper functions. (treesit--ert-defun-navigation-python-program) (treesit--ert-defun-navigation-js-program) (treesit--ert-defun-navigation-bash-program) (treesit--ert-defun-navigation-nested-master): New variables. (treesit-defun-navigation-nested-1) (treesit-defun-navigation-nested-2) (treesit-defun-navigation-nested-3) (treesit-defun-navigation-top-level): New tests.
* ; * test/src/treesit-tests.el: Add outline headers.Yuan Fu2022-12-121-0/+13
|
* Make indirect buffers use tree-sitter parsers of their base bufferYuan Fu2022-12-091-0/+34
| | | | | | | | | | | | Fix the problem described in bug#59693. * src/treesit.c (treesit_record_change): Always use the base buffer. (Ftreesit_parser_create): Always use the base buffer. Also change the for loop into FOR_EACH_TAIL (stylistic change). (Ftreesit_parser_list): Always use the base buffer. * doc/lispref/parsing.texi (Using Parser): Update manual. * test/src/treesit-tests.el (treesit-indirect-buffer): New test.
* Improve parameter checking in tree-sitter functionsYuan Fu2022-12-071-0/+8
| | | | | | | | | | | | | * src/treesit.c (treesit_check_position): Extract out new function. (Ftreesit_node_first_child_for_pos) (Ftreesit_node_descendant_for_range): Replace code with the new function. (Ftreesit_query_capture): Add missing check for node and parser. Add check for range for BEG and END. Move treesit_initialize to the beginning of the function. * test/src/treesit-tests.el (treesit-node-api) (treesit-query-api): Add tests for out-of-range error.
* ; Fix warnings in builds without tree-sitterMattias Engdegård2022-11-221-17/+47
|
* ; * test/src/treesit-tests.el (treesit-misc): Remove test.Yuan Fu2022-11-211-21/+0
| | | | | This test is for treesit--setting-for-mode, which is removed when we switched from using treesit-settings to using separate major modes.
* ; * test/src/treesit-tests.el (treesit-misc): Don't fail without tsMattias Engdegård2022-11-211-0/+1
|
* Allow checking for outdated nodes in tree-sitterYuan Fu2022-11-161-2/+5
| | | | | | | | | Now you can run (treesit-node-check node 'outdated). * doc/lispref/parsing.texi (Accessing Node Information): Update manual. * src/treesit.c (Ftreesit_node_check): Add new property 'outdated'. * test/src/treesit-tests.el (treesit-node-check): Add tests.
* ; Remove some tree-sitter testsYuan Fu2022-11-141-5/+1
| | | | | | * test/src/treesit-tests.el (treesit-parser-supplemental): Remove treesit-set-ranges, and treesit-get-ranges, as these functions are removed.
* ; * test/src/treesit-tests.el (treesit-node-check): New test.Yuan Fu2022-11-141-0/+18
|
* Improve treesit-node-atYuan Fu2022-11-111-0/+31
| | | | | | | * doc/lispref/parsing.texi (Retrieving Node): Update manual. * lisp/treesit.el (treesit-node-at): Change semantic. It tries to return the node that a user would expect in various circumstances. * test/src/treesit-tests.el (treesit-node-at): New test.
* Revise tree-sitter facility for multi-language buffersYuan Fu2022-11-041-0/+29
| | | | | | | | | | | | | | | * doc/lispref/parsing.texi (Multiple Languages): Extend and update manual. * lisp/treesit.el (treesit-range-functions): Remove variable. (treesit-range-settings): New variable. (treesit-range-rules): New function. (treesit--merge-ranges): New function. (treesit-update-ranges): Use treesit-range-settings instead of treesit-range-functions. (treesit-font-lock-rules): Fix docstring. (treesit-indent) (treesit-indent-region): Only update ranges in a region. * test/src/treesit-tests.el (treesit-range): New test.
* Remove test of treesit-language-atYuan Fu2022-10-281-3/+0
| | | | | | | | Because now it just calls a user-supplied function rather than doing any work by itself. * test/src/treesit-tests.el (treesit-parser-supplemental): Remove the test.
* ; Update copyright yearsStefan Kangas2022-10-271-1/+1
| | | | | | * doc/lispref/parsing.texi: * src/treesit.h: * test/src/treesit-tests.el: Update copyright years.
* New tree-sitter toggle schemeYuan Fu2022-10-251-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This version: central variable, everything controlled by treesit-settings. Major mode sets up tree-sitter/non-tree-sitter in a conditional branch, based on the setting. * lisp/treesit.el (treesit-settings): New option. (treesit-defun-type-regexp): Change docstring. (treesit-mode-supported) (treesit-required-languages) (treesit--local-variable-backup): Remove variables. (treesit--backup-local-variable) (treesit-mode) (global-treesit-mode--turn-on) (global-treesit-mode): Remove functions. (treesit--setting-for-mode): New function. (treesit-ready-p): New argument MODE, changed REPORT to QUIET, and LANGUAGEs to LANGUAGE (now it can be a single symbol or a list of them). (treesit-major-mode-setup): New function. Mostly comes from treesit-mode. * test/src/treesit-tests.el (treesit-misc): New test. * lisp/progmodes/python.el (python-mode): Move some setup code into the conditional branch at the end. * lisp/progmodes/js.el (js-json-mode) (js-mode): Move some setup code into the conditional branch at the end. * lisp/progmodes/ts-mode.el: Move tree-sitter setup into the conditional branch.
* Skip tree-sitter tests unless language definition is availableYuan Fu2022-10-171-0/+11
| | | | | | | | | | * test/src/treesit-tests.el (treesit-basic-parsing) (treesit-node-api) (treesit-query-api) (treesit-narrow) (treesit-cross-boundary) (treesit-multi-lang) (treesit-node-supplemental): Add skip-unless form.
* Add the treesit-search functions that supplant the removed onesYuan Fu2022-09-241-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | The signatures also changed. treesit-traverse-depth-first -> treesit-search-subtree treesit-traverse-breadth-first -> treesit-traverse-forward -> treesit-search-forward treesit-search-forward -> treesit-search-forward-goto treesit-search-beginning/end -> treesit-search-forward-goto -> treesit-induce-sparse-tree * doc/lispref/parsing.texi (Retrieving Node): Add relevant manual sections. * lisp/treesit.el (treesit-search-forward-goto): New function. * src/treesit.c (ts_traverse_sibling_helper) (ts_traverse_match_predicate) (ts_search_dfs) (ts_search_forward) (treesit-search-subtree) (treesit-search-forward) (ts_build_sparse_tree) (Ftreesit_induce_sparse_tree): Add functions. * test/src/treesit-tests.el (treesit-node-supplemental): Add comments.
* Remove treesit-traverse functionsYuan Fu2022-09-241-8/+0
| | | | | | | | | | | | | | | | | | Remove before adding the replacements. * doc/lispref/parsing.texi (Retrieving Node): Remove relevant sections. * lisp/treesit.el (treesit-traverse-depth-first) (treesit--traverse-breadth-first-1) (treesit-traverse-breadth-first) (treesit-next-sibling-or-up) (treesit-traverse-forward) (treesit-search-forward) (treesit-search-beginning): (treesit-search-end): Remove functions. (treesit-defun-query): Remove variable. (treesit-beginning-of-defun) (treesit-end-of-defun): Remove functions. * test/src/treesit-tests.el: Remove comments.