[Top][All Lists]

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

Re: treesit indentation "blinking"

From: Yuan Fu
Subject: Re: treesit indentation "blinking"
Date: Fri, 7 Apr 2023 19:42:56 -0700

> On Apr 7, 2023, at 6:32 PM, Dmitry Gutov <dmitry@gutov.dev> wrote:
> On 07/04/2023 17:20, Daniel Martín wrote:
>> In general, I'd suggest taking a look at Neovim's Tree-sitter
>> implementation and perhaps reuse (part of) their .scm Tree-sitter syntax
>> highlight or indentation queries:
>> https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries/c
>> Neovim's implementation doesn't "blink" in the scenarios presented here,
>> but I'm not sure about how it performs in other tricky cases.
> Looking at that file, it does contain queries that look for ERROR nodes, e.g.
> (
>    "for" "(" @indent.begin ";" ";" ")" @indent.end)
> So perhaps we should revisit that approach too.

Yeah, some more specific error handling can be only beneficial.

>> Now that text editors have access to the same programming language
>> grammars, I'm surprised the Tree-sitter community hasn't started any
>> cross-team effort to work on canonical queries (or slighter richer
>> abstractions) per programming language.  Text editor developers are
>> working and rediscovering complex language problems independently.
> We could do an indent implementation that just uses these indents.scm files. 
> Not exactly sure why we didn't start out this way, but note that our Lisp 
> based solution is a lot more flexible.
> E.g. there doesn't seem to be an obvious way to support "indentation styles" 
> with these.

The indent.scm way basically queries the whole file with all the queries, build 
a hash map out of the captured nodes, then get the node at the current line and 
go up the tree; at each parent, check if it’s a node that was captured, if so, 
add an indentation level.

To be honest, this will work fine in even largish files, but it’ll be slow when 
you indent a region instead of a line (in a large file). And as you said, it’s 
a bit more work to support styles. But, there are ways to make this method more 
efficient, by using some caching and localizing, so maybe it could work.

indent.scm definitely looks neater and more convenient to write than the rules 
we use (plus it already exists). So it would be nice to somehow make it 
compatible. I’ve been trying to conceive some way to convert the normal query 
into something more flexible, so that it can be used for more than querying 
“top-down” from a node. For example, verifying that a node would be captured as 
xxx in a query.

Ideas and patches are welcome :-)


reply via email to

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