emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Questions about tree-sitter


From: Yuan Fu
Subject: Re: Questions about tree-sitter
Date: Mon, 11 Sep 2023 17:22:06 -0700


> On Sep 9, 2023, at 9:39 AM, Augustin Chéneau (BTuin) <btuin@mailo.com> wrote:
> 
> Le 08/09/2023 à 18:43, Yuan Fu a écrit :
>>> On Sep 8, 2023, at 4:53 AM, Augustin Chéneau (BTuin) <btuin@mailo.com> 
>>> wrote:
>>> 
>>> Le 06/09/2023 à 06:07, Yuan Fu a écrit :
>>>> I added local parser support to master. If everything goes right, you just 
>>>> need to add a :local t flag in treesit-range-rules. Check out the modified 
>>>> bision-ts-mode.el that I hacked up for an example. BTW, it’s vital that 
>>>> you define treesit-language-at-point-function for a multi-language mode.
>>>> Yuan
>>> 
>>> Thanks a lot!
>>> 
>>> I did some tests and it's working pretty well.
>> Awesome!
> 
> 
> It seems I spoke a bit too soon  :(
> When I edit the buffer, sometimes there is an offset between the text and the 
> nodes after modifying the buffer, or the syntax highlighting breaks in C code.
> 
> I attached an example Bison file if needed.

Thanks. I was able to reproduce this, but then can’t. I’ll keep looking into 
this, if you found out something new please let me know.

> 
>>> I have a few issues though:
>>> 
>>> - I first defined `treesit-language-at-point-function` using
>>> `treesit-node-at`.  However, `treesit-node-at` itself uses
>>> `treesit-language-at-point-function` which causes an infinite recursion.
>>> So I instead used `treesit-local-parsers-at` to check if a local parser is 
>>> used.  Is it a good solution?
>> No no, you should use the host langauge’s parser (bison) and see if point is 
>> in an undelimited_code_block, and return c or bison accordingly. I’m 
>> highlight this in the docstring, thanks.
> 
> So I need to call `treesit-node-at` with `'bison` as the value for 
> PARSER-OR-LANG to see in which node I am?
> Then I think there is a problem with `treesit-node-at`, because it always 
> call `treesit-language-at` even if PARSER-OR-LANG is provided.
> I propose a fix in the attached patch.

You are right. I applied a similar fix. It should be good now. Thanks!

Yuan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]