[Top][All Lists]

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

Re: Tree sitter support for C-like languages

From: Theodor Thornhill
Subject: Re: Tree sitter support for C-like languages
Date: Tue, 15 Nov 2022 12:37:00 +0100

> We can update the nodes. (With ts_node_edit, similar to ts_tree_edit.)
> But, I looked further, and the facility for updating a node is not
> really what we need/want. I won’t go into details here, because… there
> is a feature perfect for our use case! Tree-sitter can tell you what
> has changed when you re-parse a tree, that’s exactly what we need and
> very easy to use. It’s foolish for me to overlook this feature.
> Specifically, when we re-parse a buffer, we can compare the
> before/after parse tree for differences. Tree-sitter can tell us the
> ranges in which nodes have changed during that re-parse. The “int” in
> the original example would be included in the ranges reported.
> I’ve pushed a change that utilizes this feature. If you pull the
> latest commit and open c-ts-mode, error faces should appear and
> disappear as you type. There is no documentation for now, but
> basically we now allow users to register “after-change-function”s to
> tree-sitter parsers. The parser will call these functions when with
> the changed ranges when it re-parses.
> The new functions are treesit-parser-add-notifier,
> treesit-parser-notifiers, treesit-parser-remove-notifier. I didn’t use
> treesit-parser-add-after-change-function because that is hideously
> long.

It works like a charm!  Great job :-)


reply via email to

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