From: Dmitry Gutov <dmitry@gutov.dev>
To: Felix <felix.dick@web.de>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Tree-sitter navigation time grows as sqrt(line-number)
Date: Thu, 17 Aug 2023 18:01:19 +0300 [thread overview]
Message-ID: <2fe95bcd-c3b5-09de-067d-fe986b01f890@gutov.dev> (raw)
In-Reply-To: <f5143dab-257c-ccc6-f5fa-f624312828de@gutov.dev>
[-- Attachment #1: Type: text/plain, Size: 1557 bytes --]
On 17/08/2023 17:36, Dmitry Gutov wrote:
> On 17/08/2023 17:25, Dmitry Gutov wrote:
>> On 17/08/2023 17:08, Felix wrote:
>>> Hi,
>>>
>>> I tried that patch, and it crashes emacs whenever i try to scroll inside
>>> a tree-sitter managed buffer.
>>>
>>> GNU Emacs 30.0.50 (build 22, x86_64-pc-linux-gnu, GTK+ Version
>>> 3.24.38, cairo version 1.17.8) of 2023-08-17
>>>
>>> compiled with pgtk running on wayland.
>>
>> Thanks for testing. Does that happen in any ts mode, or some
>> particular ones?
>>
>> If you run Emacs from the terminal, could you post the error backtrace?
>>
>> (Please keep emacs-devel in Cc).
>
> For my part, I don't see it crash when scrolling (in ruby-ts-mdoe or
> js-ts-mode, including larges files), but the test scenario by JD does
> make it crash.
>
> When running under GDB, the backtrace simply looks like this:
>
> #0 0x00007ffff63bf93d in ts_tree_root_node (self=0x0) at lib/src/tree.c:36
> #1 0x00007ffff63a54e5 in ts_node_parent (self=...) at lib/src/node.c:462
> #2 0x00005555557f0d17 in Ftreesit_node_parent
> (node=XIL(0x5555574908c5)) at treesit.c:1906
> #3 0x000055555576f62b in eval_sub (form=<optimized out>) at eval.c:2511
> #4 0x000055555576f987 in Fsetq (args=<optimized out>) at eval.c:483
> #5 0x000055555576f368 in eval_sub (form=<optimized out>) at eval.c:2462
> #6 0x000055555576ff75 in Fprogn (body=XIL(0)) at eval.c:436
> ...
Try this one.
I've read the tree-sitter docs a bit more, and also dropped the "else"
case because it was unreachable anyway. I doesn't crash anymore here.
[-- Attachment #2: treesit-node-parent.diff --]
[-- Type: text/x-patch, Size: 1199 bytes --]
diff --git a/src/treesit.c b/src/treesit.c
index 1f694e47201..46fbacaefe3 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -52,6 +52,7 @@ Copyright (C) 2021-2023 Free Software Foundation, Inc.
#undef ts_node_named_descendant_for_byte_range
#undef ts_node_next_named_sibling
#undef ts_node_next_sibling
+#undef ts_node_parent
#undef ts_node_prev_named_sibling
#undef ts_node_prev_sibling
#undef ts_node_start_byte
@@ -1895,21 +1896,15 @@ DEFUN ("treesit-node-parent",
treesit_check_node (node);
treesit_initialize ();
- Lisp_Object return_value = Qnil;
-
TSNode treesit_node = XTS_NODE (node)->node;
Lisp_Object parser = XTS_NODE (node)->parser;
- TSTreeCursor cursor;
- if (!treesit_cursor_helper (&cursor, treesit_node, parser))
- return return_value;
- if (ts_tree_cursor_goto_parent (&cursor))
- {
- TSNode parent = ts_tree_cursor_current_node (&cursor);
- return_value = make_treesit_node (parser, parent);
- }
- ts_tree_cursor_delete (&cursor);
- return return_value;
+ TSNode parent = ts_node_parent (treesit_node);
+
+ if (ts_node_is_null (parent))
+ return Qnil;
+
+ return make_treesit_node (parser, parent);
}
DEFUN ("treesit-node-child",
next prev parent reply other threads:[~2023-08-17 15:01 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87v8ddsqwe.fsf@web.de>
2023-08-17 14:25 ` Tree-sitter navigation time grows as sqrt(line-number) Dmitry Gutov
2023-08-17 14:36 ` Dmitry Gutov
2023-08-17 15:01 ` Dmitry Gutov [this message]
2023-08-17 15:15 ` Felix
2023-08-18 2:49 ` Yuan Fu
2023-08-18 13:29 ` Dmitry Gutov
2023-08-17 4:01 JD Smith
2023-08-17 10:56 ` Dmitry Gutov
2023-08-17 11:41 ` Eli Zaretskii
2023-08-17 11:51 ` tomas
2023-08-17 12:21 ` JD Smith
2023-08-17 12:34 ` Dmitry Gutov
2023-08-17 13:19 ` Dmitry Gutov
2023-08-19 14:24 ` JD Smith
2023-08-19 22:16 ` Yuan Fu
2023-08-20 0:18 ` JD Smith
2023-08-20 0:39 ` Dmitry Gutov
2023-08-20 2:01 ` Yuan Fu
2023-08-20 12:40 ` JD Smith
2023-08-20 20:26 ` Dmitry Gutov
2023-08-22 1:41 ` Yuan Fu
2023-08-22 21:07 ` JD Smith
2023-08-31 4:26 ` Yuan Fu
2023-08-31 6:03 ` Eli Zaretskii
2023-08-31 11:04 ` Dmitry Gutov
2023-08-31 11:42 ` Po Lu
2023-08-31 17:32 ` Dmitry Gutov
2023-08-31 12:51 ` Eli Zaretskii
2023-08-31 13:58 ` JD Smith
2023-08-31 17:49 ` Dmitry Gutov
2023-08-31 19:03 ` Yuan Fu
2023-08-31 19:06 ` Eli Zaretskii
2023-08-31 20:24 ` Stefan Kangas
2023-09-01 5:33 ` Eli Zaretskii
2023-08-20 6:18 ` Eli Zaretskii
2023-08-18 3:00 ` Yuan Fu
2023-08-18 4:19 ` JD Smith
2023-08-18 5:20 ` Yuan Fu
2023-08-18 13:21 ` Dmitry Gutov
2023-08-18 13:39 ` JD Smith
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2fe95bcd-c3b5-09de-067d-fe986b01f890@gutov.dev \
--to=dmitry@gutov.dev \
--cc=emacs-devel@gnu.org \
--cc=felix.dick@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).