[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tree-sitter: proper use of parser-set-included-ranges
|
From: |
Yuan Fu |
|
Subject: |
Re: tree-sitter: proper use of parser-set-included-ranges |
|
Date: |
Fri, 25 Aug 2023 00:28:20 -0700 |
> On Aug 23, 2023, at 6:58 AM, JD Smith <jdtsmith@gmail.com> wrote:
>
> `treesit-parser-set-included-ranges’ appears quite useful for directing
> tree-sitter’s attention to part of a buffer, for example input at a comint
> mode’s prompt. But I have noticed that once the included range is set, it
> remains fixed within the buffer, and does not expand as text is added or
> removed from that region.
>
> Since tree-sitter incrementally updates the syntax tree as edits occur, I
> wonder what the “right time” to update the included region with
> `set-included-ranges’ is? Constantly, say in an after-change-function, or
> “just-in-time”, as you are about to query the syntax tree for some purpose?
Usually you’d want to do it less often, since usually you need to query the
“base” language for the range before setting the range for the embedded
language. Other than that I don’t think it makes a big difference either way.
>
> Put another way, does the syntax tree in tree-sitter survive changes to an
> included range (treating it as an “incremental update”)? Or does explicitly
> changing the range effectively dump the tree and rebuild it?
IIUC the parse tree is preserved. That makes the most sense to me.
Yuan