From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Tree sitter support for C-like languages Date: Tue, 15 Nov 2022 17:03:39 +0200 Message-ID: <83a64si7jo.fsf@gnu.org> References: <87tu36em9t.fsf@thornhill.no> <45FD2F78-F15B-488B-9348-A8E298D8AD35@gmail.com> <87v8nmyqqp.fsf@thornhill.no> <834jv4nz2g.fsf@gnu.org> <871qq8hsj1.fsf@thornhill.no> <83iljklzmo.fsf@gnu.org> <87v8nkgcqj.fsf@thornhill.no> <87sfiogcbm.fsf@thornhill.no> <83pmdrkyj7.fsf@gnu.org> <87v8njw5th.fsf@thornhill.no> <83leofkwjm.fsf@gnu.org> <9E9244D3-2EFB-4621-91E0-FC8B8C1C2D52@gmail.com> <186915C1-1C47-43DC-A386-B447A2E7528D@gmail.com> <83h6z1k6z8.fsf@gnu.org> <52D18BA8-C9A8-4E9A-9DDA-76E48744DDC9@gmail.com> <837czxjrxu.fsf@gnu.org> <8BEF109A-A5B3-4CF4-AE07-AEB9388B0A07@gmail.com> <83zgcti9gh.fsf@gnu.org> <83y1scj3s8.fsf@gnu.org> <7082237A-2BD6-4A1C-8BEC-4D470B0D204F@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34335"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, theo@thornhill.no, emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 15 16:04:28 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ouxUB-0008j9-UM for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Nov 2022 16:04:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxTK-0000Nw-Di; Tue, 15 Nov 2022 10:03:34 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouxTF-0000NZ-I2 for emacs-devel@gnu.org; Tue, 15 Nov 2022 10:03:32 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouxTE-0002W7-Hb; Tue, 15 Nov 2022 10:03:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=mFbb30oDTAOL9suEcpH1ImFI8hhGngPpMu/FAISq83c=; b=YeCI++oXlJutPhcTqo7j y90vCbEy8ITymzIIPuRIqvRiKJY6R+PCMx4f+/P2Gka61pMF8kiOg6ufKfE2ilySxwwN9idWKi+Mu EChsgIffTU9myr5JO0bbBhQMlbO2b98JbpzruokwLYCXu4RbhXwdN2goxI91d+6RIMLW5n/tY9Y98 oIW0jaudXBNmNGi2wdIw2GEVfgzb6MRa+Eq2MDxQjixAQ1I9+lXrxqaSkQ7zJXK65M37W1zJ8Z3lX hrNrKOQp+GUqJzT78tGp4iRnIT4LaY2x1RladZ7G79bEWaWEzfwY/BKRYJCGFVAAhmqHJHNd+NJqx LlwAsPYUze14Fw==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouxTC-0007r6-0Z; Tue, 15 Nov 2022 10:03:27 -0500 In-Reply-To: <7082237A-2BD6-4A1C-8BEC-4D470B0D204F@gmail.com> (message from Yuan Fu on Tue, 15 Nov 2022 02:51:31 -0800) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:299850 Archived-At: > From: Yuan Fu > 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?