[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to add pseudo vector types
From: |
Fu Yuan |
Subject: |
Re: How to add pseudo vector types |
Date: |
Tue, 3 Aug 2021 08:00:46 -0400 |
> 在 2021年8月3日,上午7:48,Eli Zaretskii <eliz@gnu.org> 写道:
>
>
>>
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Fri, 30 Jul 2021 10:17:22 -0400
>> Cc: Stephen Leake <stephen_leake@stephe-leake.org>,
>> Clément Pit-Claudel <cpitclaudel@gmail.com>,
>> Stefan Monnier <monnier@iro.umontreal.ca>,
>> emacs-devel@gnu.org
>>
>>> That said, it looks like the code is correct: you should record the
>>> changes in the entire buffer, but only pass to TS the changes inside
>>> the restriction BEGV..ZV that is in effect at the time of the re-parse
>>> call. Btw, I don't see the code that filters changes reported to TS
>>> by their positions against the restriction; did I miss something?
>>
>> Yes, I do clip the change to the visible portion:
>>
>> ts_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte,
>> ptrdiff_t new_end_byte)
>> {
>> eassert(start_byte <= old_end_byte);
>> eassert(start_byte <= new_end_byte);
>>
>> Lisp_Object parser_list = Fsymbol_value (Qtree_sitter_parser_list);
>>
>> while (!NILP (parser_list))
>> {
>> Lisp_Object lisp_parser = Fcar (parser_list);
>> TSTree *tree = XTS_PARSER (lisp_parser)->tree;
>> if (tree != NULL)
>> {
>> /* We "clip" the change to between visible_beg and
>> visible_end. It is okay if visible_end ends up larger
>> than BUF_Z, tree-sitter only access buffer text during
>> re-parse, and we will adjust visible_beg/end before
>> re-parse. */
>> ptrdiff_t visible_beg = XTS_PARSER (lisp_parser)->visible_beg;
>> ptrdiff_t visible_end = XTS_PARSER (lisp_parser)->visible_end;
>>
>> ptrdiff_t visible_start =
>> max (visible_beg, start_byte) - visible_beg;
>> ptrdiff_t visible_old_end =
>> min (visible_end, old_end_byte) - visible_beg;
>> ptrdiff_t visible_new_end =
>> min (visible_end, new_end_byte) - visible_beg;
>>
>> ts_tree_edit_1 (tree, visible_start, visible_old_end,
>> visible_new_end);
>> XTS_PARSER (lisp_parser)->need_reparse = true;
>>
>> parser_list = Fcdr (parser_list);
>
> Hmm... so a change that begins before the restriction and ends inside
> the restriction will be sent as if it began at BEGV? And the rest of
> the change will be discarded? Shouldn't you split such changes in
> tow, send to TS the part inside the restriction, and store the rest
> for the future, when/if the buffer is widened?
Tree-sitter doesn’t care about the content in a change, it will re-scan the
buffer content when it re-parses. We only need to inform it the range of the
change, so it knows where to re-scan when it re-parses. When the buffer is
widened, we will tell tree-sitter that range [BUF_BEG, BUF_BEGV] has changed,
and it will re-scan that part when re-parsing. So the part outside the narrowed
region will be parsed correctly.
Yuan
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/08/03
- Re: How to add pseudo vector types,
Fu Yuan <=
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/08/03
- Re: How to add pseudo vector types, Fu Yuan, 2021/08/03
- Re: How to add pseudo vector types, Stefan Monnier, 2021/08/03
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/08/03
- Re: How to add pseudo vector types, Yuan Fu, 2021/08/05
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/08/06
- Tree-sitter api (Was: Re: How to add pseudo vector types), Fu Yuan, 2021/08/07
- Re: Tree-sitter api (Was: Re: How to add pseudo vector types), Eli Zaretskii, 2021/08/07
- Re: Tree-sitter api, Stefan Monnier, 2021/08/07
- Re: Tree-sitter api, Theodor Thornhill, 2021/08/07