unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* tree-sitter: proper use of parser-set-included-ranges
@ 2023-08-23 13:58 JD Smith
  2023-08-25  7:28 ` Yuan Fu
  0 siblings, 1 reply; 2+ messages in thread
From: JD Smith @ 2023-08-23 13:58 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 855 bytes --]

`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? 

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?


[-- Attachment #2: Type: text/html, Size: 1220 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: tree-sitter: proper use of parser-set-included-ranges
  2023-08-23 13:58 tree-sitter: proper use of parser-set-included-ranges JD Smith
@ 2023-08-25  7:28 ` Yuan Fu
  0 siblings, 0 replies; 2+ messages in thread
From: Yuan Fu @ 2023-08-25  7:28 UTC (permalink / raw)
  To: JD Smith; +Cc: emacs-devel



> 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-25  7:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-23 13:58 tree-sitter: proper use of parser-set-included-ranges JD Smith
2023-08-25  7:28 ` Yuan Fu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).