From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#72184: 31.0.50; typescript-ts-mode does not bind RET to newline-and-indent Date: Thu, 1 Aug 2024 03:42:27 +0300 Message-ID: References: <31020dbe-3268-47e3-94c9-8c7acef452fd@gutov.dev> <8634nv2tcq.fsf@gnu.org> <5088180E-50DC-4374-B7F3-78DA6244291C@secure.kjonigsen.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3971"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: Yuan Fu , acorallo@gnu.org, Theodor Thornhill , 72184@debbugs.gnu.org To: Jostein =?UTF-8?Q?Kj=C3=B8nigsen?= , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 01 02:43:04 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1sZJuI-0000oc-Gb for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Aug 2024 02:43:02 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZJu5-0003hS-Vk; Wed, 31 Jul 2024 20:42:50 -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 1sZJu2-0003PW-2W for bug-gnu-emacs@gnu.org; Wed, 31 Jul 2024 20:42:46 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZJu1-0003iH-Pw for bug-gnu-emacs@gnu.org; Wed, 31 Jul 2024 20:42:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:From:References:MIME-Version:Date:To:Subject; bh=28LMmB5jdjgCo7t8aCOLXk+6g28LzGF015vEXkiguaU=; b=Jo+E2j5qnyd3ZNJVTSZ/jXzj6h3O4waC/NgvU8RYN0SrGeLVPNo2A9mpe44bS7qGYySMFkS7ZY2XHKY+yn1j0IRv1L2UlsWu7UU7bOpAOd4FCupukBPLDXePh1wQhgFTgTxkq3GJCpTC5TPw5sh1+6G6xGAIYXNazaoBGNuk8aIUzmz+rK5n5DKEgaz2fvHypvdoWu4Bbj8fed1+aDSWoX5n13HC9vb9PIUHJ15dAxPQ9uLylvEjbLOUgOvNDcGD5WoUW2vsnnH0oAJldP1yHrZND8NTgDPbiejV08E/1nBDYpnDw6PX4PI+8s5KVSQHsLRfo6ZfkcRYj/ZW3GORfA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sZJuH-0000dA-M0 for bug-gnu-emacs@gnu.org; Wed, 31 Jul 2024 20:43:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Aug 2024 00:43:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72184 X-GNU-PR-Package: emacs Original-Received: via spool by 72184-submit@debbugs.gnu.org id=B72184.17224729762414 (code B ref 72184); Thu, 01 Aug 2024 00:43:01 +0000 Original-Received: (at 72184) by debbugs.gnu.org; 1 Aug 2024 00:42:56 +0000 Original-Received: from localhost ([127.0.0.1]:50454 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sZJuB-0000cr-Qy for submit@debbugs.gnu.org; Wed, 31 Jul 2024 20:42:56 -0400 Original-Received: from fhigh4-smtp.messagingengine.com ([103.168.172.155]:56015) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sZJu9-0000ce-Fu for 72184@debbugs.gnu.org; Wed, 31 Jul 2024 20:42:53 -0400 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 25FA81140350; Wed, 31 Jul 2024 20:42:32 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 31 Jul 2024 20:42:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1722472952; x=1722559352; bh=28LMmB5jdjgCo7t8aCOLXk+6g28LzGF015vEXkiguaU=; b= dRRMwrzTLcWtyjLpuIxNJ1sguGAAr3I+ndFO/MXZJMFyCSyqBJgFWGabBh4QsRoJ V90UEoifwTMrNjJi7a9BI4tO3ZtCNF6lYHl177Tfb7uHNWmSdbvJ69yRRi57+dQp zEQDKETdDDQ3csWFtTF4ompE5dKmO2jKuWKLanE6ciM5Gw6CrXZcDKEhL4ai8U8I Rb1gOhoEjTBCfStFRPPPb2P8k76rvJzFv1GxPGhCqpic+oc7WGPl4dW2lmZEGGEj ZGuiLYsqmHv0f8Tacjlzygn8zpcU0IqOQeIPIvMTNFugmkgvO15XMi+MeZSiUwfm Ztz6yYpHPQI8f+bbFhhy1w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1722472952; x= 1722559352; bh=28LMmB5jdjgCo7t8aCOLXk+6g28LzGF015vEXkiguaU=; b=Z nsaeYU79thcqBzZUJquLP9rvCO4IP9OGpihDEIS4ftAmP5uZQ37MeWgQdpHMdsvA mPRI5aidy6lxtZdMmw310IGmGUPCTfiEDcytZYWOZ4771blLqW9dUOR5o6/ZfZAa BFa7aYrfpImfK50BwP2IhC41d/KWFD1kUDt+muMeHMD+/kvUJu5oRp22eFfj+61V v4rN3Tm9HZAcjY1ANKmkZ/QS975aTTZjblj5hg9d7xzTBicaRKz13+5Jnq50DjAe WmIeJLtcce6mWT+bfBcn/A8SPNYqh2zrv0FJOoiannfVmMS8UNsTliX5oQ18B53S z+ZKr4UGfkbXnzZTDbpTA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeejgdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomhepffhmihht rhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrdguvghvqeenucggtffrrghtth gvrhhnpeeuteduhfeitdejkeeuffefhefgffevveetjedthfetteegtefhveeujeekjefg veenucffohhmrghinhepghhnuhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpegumhhithhrhiesghhuthhovhdruggvvhdpnhgspghr tghpthhtoheptd X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 31 Jul 2024 20:42:29 -0400 (EDT) Content-Language: en-US In-Reply-To: <5088180E-50DC-4374-B7F3-78DA6244291C@secure.kjonigsen.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:289594 Archived-At: Hi Jostein, On 31/07/2024 11:55, Jostein Kjønigsen wrote: > PREFACE > > I've now looked further into this issue, and what we're actually seeing > here is not indentation code "not working", but indentation rules not > taking into account incomplete parse-trees while code is being written. Makes sense, thanks. > So as the original bug-submitter, I will have to just declare that the > original bug-description is clearly inaccurate. Sorry about that! > > Below is my attempt to better express what is actually failing and why. > > *My hypothesis is that this could be an issue for other tree-sitter > based major-modes as well, and maintainers of those modes are encouraged > to check for similar issues.* > > If more major-modes than typescript-ts-mode is affected, the optimum > solution may best be decided together, rather than individually per mode. > > AS FOR THE BUG - DETAILS > > Consider the following pre-existing typescript/javascript function: > > function stuff() { >   // TODO implement > } > > > Using the typescript tree-sitter grammer, it gets the following nodes in > its tree-sitter AST: > >  (function_declaration function name: (identifier) >   parameters: (formal_parameters ( )) >   body: (statement_block { (comment) })) > > This matches the rules for indentation in typescript-ts-mode and indents > correctly regardless. > > But in a bare config with only electric-indent-mode enabled (and not > electric-pair-mode), trying to enter a new function will produce a > incomplete syntax tree, due to the missing final brace. > > The code will look like this: > > function gnu2() {  // NOTE: no closing brace! > > > And the tree-sitter AST will then look like this until completed: > >  (expression_statement >   (function function name: (identifier) >    parameters: (formal_parameters ( )) >    body: (statement_block { (comment) })))) > > > And typescript-ts-mode has no indentation rules for this AST. *Thus > pressing enter wont cause indentation, despite electric-indent-mode > being enabled.* > > I suspect this sort of issue could possibly affect other treesitter > based modes which has been developed mostly in existing configs with > "all the bells and whistles" (like electric-pair-mode) enabled. > > I'll hold off any fixes or suggestions for such until we have some > reports from other maintainers, if that is ok? We've seen this before - take a look at https://debbugs.gnu.org/62717, for example. In short, some ad-hoc counter-measures can and sometimes are added (proposals welcome), but ultimately when we know we can't reliably distinguish problem situations, or can only detect a minor fraction of them, we're also okay giving up and recommending people use electric-pair-mode for better experience.