emacs-devel
[Top][All Lists]
Advanced

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

Re: Tree sitter support for C-like languages


From: Eli Zaretskii
Subject: Re: Tree sitter support for C-like languages
Date: Tue, 15 Nov 2022 17:03:39 +0200

> From: Yuan Fu <casouri@gmail.com>
> Date: Tue, 15 Nov 2022 02:51:31 -0800
> Cc: monnier@iro.umontreal.ca,
>  theo@thornhill.no,
>  emacs-devel@gnu.org
> 
> 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.

Thanks, this works very well.  I think we can consider this issue
resolved.

Btw, I now see that some parts of our sources are displayed in warning
face, probably because Tree-sitter cannot cope with our macro usage.
For example:

  DEFUN ("set-buffer-redisplay", Fset_buffer_redisplay,
         Sset_buffer_redisplay, 4, 4, 0,
         doc: /* Mark the current buffer for redisplay.
  This function may be passed to `add-variable-watcher'.  */)
    (Lisp_Object symbol, Lisp_Object newval, Lisp_Object op, Lisp_Object where)
  {

This shows all the arguments in warning face.

  static void ATTRIBUTE_FORMAT_PRINTF (1, 2)
  redisplay_trace (char const *fmt, ...)
  {

This shows "1, 2" and "redisplay_trace" in warning face.

  extern bool trace_move EXTERNALLY_VISIBLE;

This shows "trace_move" in the warning face.

  #ifdef HAVE_WINDOW_SYSTEM
        if (part == ON_LEFT_MARGIN || part == ON_RIGHT_MARGIN)
          {
            cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
            /* Show non-text cursor (Bug#16647).  */
            goto set_cursor;
          }
        else
  #endif
          return;

This shows "else" in the warning face.

I guess we need to report these to the developers of the Tree-sitter's
C parser?  Is there anything else we could do until they fix the
parser?



reply via email to

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