[Top][All Lists]

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

Re: How to add pseudo vector types

From: Yuan Fu
Subject: Re: How to add pseudo vector types
Date: Thu, 29 Jul 2021 10:35:10 -0400

>> That makes sense. However it bring up a problem. Consider such a buffer: 
>> XXAAXX. Say lisp narrows to AA and creates a tree-sitter parser. Then lisp 
>> widens the buffer, and user inserts B in front of AA. Now the buffer is 
>> XXBAAXX. Emacs has two options to convey this change to the tree-sitter 
>> parser: 1) it does not, then tree-sitter still thinks the buffer is AA, 
>> essentially the portion where tree-sitter sees is pushed forward by one 
>> character, 2) it tells tree-sitter the user inserted a character at the 
>> beginning, then tree-sitter thinks the buffer is BAA. Which option is 
>> correct depends on how does lisp later narrows: if lisp narrows to AA, then 
>> option 1 is correct, if lisp narrows to BAA, then option 2 is correct. But 
>> how do we know which option is correct before lisp narrows?
> We don't need to know.  The Lisp program which needs to handle this
> situation will have to figure out what is right in that case, "right"
> in the sense that it produces the desired results after communicating
> the changes to TS.

The difficulty is that what tree-sitter sees must be consistent. If Emacs 
updates tree-sitter with option 1 and lisp later choose option 2, the content 
that tree-sitter sees is not consistent. Anyway, I found a way that avoids this 
issue: the bounds of tree-sitter’s visible region never changes, and the next 
time when lisp narrows to a different region, we update tree-sitter’s bound to 
match that of the narrowing. Here is the latest patch. If the code is not 
entirely straightforward, I’m happy to add more comment to explain it.

I set up a linux machine and tried to debug the crashing problem, but it didn’t 
crash. Seems the crash only appears on my Mac...


Attachment: ts.5.patch
Description: Binary data

reply via email to

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