From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: Re: treesit indentation "blinking" Date: Thu, 23 Mar 2023 17:10:53 -0400 Message-ID: <187104f6b48.2829.cc5b3318d7e9908e2c46732289705cb0@dancol.org> References: <87h6ucik61.fsf@dancol.org> <0F406D08-56D4-4B21-B94D-A47681606911@gmail.com> <1870bcadd28.2829.cc5b3318d7e9908e2c46732289705cb0@dancol.org> <1870cce6690.2829.cc5b3318d7e9908e2c46732289705cb0@dancol.org> <35A837A9-59B4-4F1F-A5FA-8483C8024D76@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="187104f6e1d7050282990b69e3" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="596"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: AquaMail/1.43.0 (build: 104300275) Cc: To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Mar 23 22:11:38 2023 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 1pfSDh-000ATW-AY for ged-emacs-devel@m.gmane-mx.org; Thu, 23 Mar 2023 22:11:37 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pfSD7-00037Z-4v; Thu, 23 Mar 2023 17:11:01 -0400 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 1pfSD4-00037M-Uj for emacs-devel@gnu.org; Thu, 23 Mar 2023 17:10:58 -0400 Original-Received: from dancol.org ([2600:3c01:e000:3d8::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pfSD2-0005eq-Kk for emacs-devel@gnu.org; Thu, 23 Mar 2023 17:10:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dancol.org; s=x; h=Content-Type:MIME-Version:Subject:References:In-Reply-To:Message-ID: Date:CC:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ockfkDq4B/oVcAoa9DwLCKEKC+Gv58jgUBTJVrqKTqI=; b=bRVBW0cXaFCFooIo8hipE3sK69 mnXalYP5whEgG5karo8GVaL88591UkoD2ObvfzUu6cfdAPWQHFix5U+5l3mlBkUleU3tKUnJq2vF9 61xuKYTjPTatyZHMM1ujGmPnoaxLBjM1MVm5kHayIazqS942QJIiTBDi+ZS7nxYQ7HLvdueQF1eKV GldcUdl+GNZlHyBdZ+Z5bZa69jVhQDktibo/BwJKb+Zu0TBpvgbbhmWGUwtAIiLm4Yv7yX9KeZSWs KG3S9Ch1Jtp+garoM968jAFWosIcKm9Nf5fxAsHLbyMjoodVaU90cxVT06x9xN5eZXyRg2jrqahUD WoXClgfg==; Original-Received: from 154.sub-174-239-64.myvzw.com ([174.239.64.154]:8716 helo=[100.126.35.25]) by dancol.org with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1pfSD0-0004Kv-CB; Thu, 23 Mar 2023 14:10:55 -0700 In-Reply-To: <35A837A9-59B4-4F1F-A5FA-8483C8024D76@gmail.com> Received-SPF: pass client-ip=2600:3c01:e000:3d8::1; envelope-from=dancol@dancol.org; helo=dancol.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:304741 Archived-At: This is a multi-part message in MIME format. --187104f6e1d7050282990b69e3 Content-Type: text/plain; format=flowed; charset="UTF-8" Content-Transfer-Encoding: 8bit On March 23, 2023 16:04:16 Yuan Fu wrote: >> On Mar 22, 2023, at 9:51 PM, Daniel Colascione wrote: >> >> On March 22, 2023 21:03:29 Yuan Fu wrote: >> >>>> On Mar 22, 2023, at 5:07 PM, Daniel Colascione wrote: >>>> >>>> >>>> >>>> On March 22, 2023 20:00:23 Yuan Fu wrote: >>>> >>>>>> On Mar 22, 2023, at 1:49 PM, Daniel Colascione wrote: >>>>>> >>>>>> Is there a general-purpose through which we can avoid line indentation >>>>>> oscillating as the user types when the AST is temporarily invalid, >>>>>> e.g. after '(' or '{'? I'm checking out the C++ tree-sitter mode, and >>>>>> one of the more disconcerting things is the current line's indentation >>>>>> changing rapidly as I type. Is it feasible to create ERROR recovery >>>>>> indentation rules for every conceivable situation? >>>>> >>>>> Yes, but in reality, I think all we need is a couple special case for the >>>>> unmatched ( and {’s. Can you think of other cases of blinking indentations? >>>>> >>>>> Yuan >>>> >>>> But TS reacts to missing closing brackets by clarifying the whole nearby >>>> expression as ERROR. It's not, as would be more useful, saying "here's a >>>> stray (, and everything else is normal and parsed as if that ( were absent” >>> >>> We can just look at the buffer text directly: if there’s an ERROR and the >>> previous char (after skipping whitespace chars) is ( or {, we know what to do >> >> >> Do we know what to do? That ERROR might be arbitrarily far up the parse >> tree. I don't think it's as easy as you think it might be. One strategy >> that might work is to see whether adding a "(" introduced an error, and, if >> so, temporarily replacing that "(" with whitespace, reparsing, and then >> using the resulting parse tree instead of the one with the "(" to do >> indentation and fontification. This way, I think you'd end up without the >> random jumping around we see today in TS modes. > > We can place this special rule at the end of our rule list, and previous > rules not matching should indicated “error” by itself. Of course, I can’t > prove it by using this method to fix the blinking indent, but I don’t quite > have the time for it right now. Editing can cause all sorts of transient nonsense in the AST, and it's impossible to predict in a general manner what this nonsense might be. The wrong kind of bracket can cause the entire rest of the file to be parsed as nonsense. This or that error recovery rule isn't going to solve the problem: such a strategy is a fragile whack a mole. There needs to be some general solution to prevent indentation blinking. This blinking makes TS modules unusable for me. --187104f6e1d7050282990b69e3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On March 23, 2023 16:04:16 Yuan Fu <casouri@gmail.com&= gt; wrote:

On Mar 22, 2023, at 9:51 PM, Daniel Colascione <dancol= @dancol.org> wrote:

On March 22, 2023 21:03:29 Yuan Fu <casouri@gmail.com&= gt; wrote:

On Mar 22, 2023, at 5:07 PM, Daniel Colascione <dancol= @dancol.org> wrote:



On March 22, 2023 20:00:23 Yuan Fu <casouri@gmail.com&= gt; wrote:

On Mar 22, 2023, at 1:49 PM, Daniel Colascione <dancol= @dancol.org> wrote:

Is there a general-purpose through which we can avoid lin= e indentation
oscillating as the user types when the AST is temporarily= invalid,
e.g. after '(' or '{'? I'm checking out the C++ tree-sitt= er mode, and
one of the more disconcerting things is the current line'= s indentation
changing rapidly as I type. Is it feasible to create ERRO= R recovery
indentation rules for every conceivable situation?


Yes, but in reality, I think all we need is a couple spec= ial case for the unmatched ( and {=E2=80=99s. Can you think of other cases = of blinking indentations?

Yuan

But TS reacts to missing closing brackets by clarifying t= he whole nearby expression as ERROR. It's not, as would be more useful, say= ing "here's a stray (, and everything else is normal and parsed as if that = ( were absent=E2=80=9D

We can just look at the buffer text directly: if there=E2= =80=99s an ERROR and the previous char (after skipping whitespace chars) is= ( or {, we know what to do


Do we know what to do? That ERROR might be arbitrarily fa= r up the parse tree. I don't think it's as easy as you think it might be. O= ne strategy that might work is to see whether adding a "(" introduced an er= ror, and, if so, temporarily replacing that "(" with whitespace, reparsing,= and then using the resulting parse tree instead of the one with the "(" to= do indentation and fontification. This way, I think you'd end up without t= he random jumping around we see today in TS modes.

We can place this special rule at the end of our rule lis= t, and previous rules not matching should indicated =E2=80=9Cerror=E2=80=9D= by itself. Of course, I can=E2=80=99t prove it by using this method to fix= the blinking indent, but I don=E2=80=99t quite have the time for it right = now.

=
Editing can cause all sorts of transient nonsen= se in the AST, and it's impossible to predict in a general manner what this= nonsense might be. The wrong kind of bracket can cause the entire rest of = the file to be parsed as nonsense. This or that error recovery rule isn't g= oing to solve the problem: such a strategy is a fragile whack a mole. There= needs to be some general solution to prevent indentation blinking. This bl= inking makes TS modules unusable for me.

--187104f6e1d7050282990b69e3--