From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jostein =?UTF-8?Q?Kj=C3=B8nigsen?= Newsgroups: gmane.emacs.bugs Subject: bug#72184: 31.0.50; typescript-ts-mode does not bind RET to newline-and-indent Date: Wed, 31 Jul 2024 10:55:00 +0200 Message-ID: <5088180E-50DC-4374-B7F3-78DA6244291C@secure.kjonigsen.net> References: <31020dbe-3268-47e3-94c9-8c7acef452fd@gutov.dev> <8634nv2tcq.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_6701E944-F619-4FF0-9B13-B7EBAE0B36FD" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1770"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Dmitry Gutov , Yuan Fu , acorallo@gnu.org, Theodor Thornhill , 72184@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jul 31 10:56:07 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 1sZ57u-0000Ex-DN for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 31 Jul 2024 10:56:07 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZ57e-0007lU-3k; Wed, 31 Jul 2024 04:55: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 1sZ57b-0007cn-T6 for bug-gnu-emacs@gnu.org; Wed, 31 Jul 2024 04:55:48 -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 1sZ57b-00063y-Fs for bug-gnu-emacs@gnu.org; Wed, 31 Jul 2024 04:55:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:Date:Mime-Version:From:To:Subject; bh=nVKEAQNYBaY4kafUFwGoMg+TGQpTqX9X6vy2+ihdXhw=; b=u4YaXqKsU75N1KIQpbyynqonO6Kdf6WdngtSBgIwyFvBPMxsPy20TXnCNRsdJotExkbKabqk05eye28HNsPABi73VNNFCX0ywlDVcIZ9I1wo8hiAcwlGXMhm7nFJzgQNhaSAshkh+XuhDUFvr4LJQuvaMSNVW1C2ZeZGztAePsNPuvC1rxat47qEPhspTEznSvtXusaE/s5eD/Bcxb0wsz7DBOrKXs3CaFh9y0tCmuV+J2u2uZknX3e9J+w9uwbAUBr6m7u4TgpIVh82603naGoM7HlTJJrSnimjcSkxGkdbxEELwzJGThJBExuT1d1bRm28SE+EU+m3vdxf5VcsCQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sZ57q-0001XR-9o for bug-gnu-emacs@gnu.org; Wed, 31 Jul 2024 04:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jostein =?UTF-8?Q?Kj=C3=B8nigsen?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 31 Jul 2024 08:56:02 +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.17224161505895 (code B ref 72184); Wed, 31 Jul 2024 08:56:02 +0000 Original-Received: (at 72184) by debbugs.gnu.org; 31 Jul 2024 08:55:50 +0000 Original-Received: from localhost ([127.0.0.1]:49087 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sZ57d-0001X1-BT for submit@debbugs.gnu.org; Wed, 31 Jul 2024 04:55:49 -0400 Original-Received: from fhigh2-smtp.messagingengine.com ([103.168.172.153]:55197) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sZ57Z-0001Wi-FC for 72184@debbugs.gnu.org; Wed, 31 Jul 2024 04:55:47 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 07CF41146E7B; Wed, 31 Jul 2024 04:55:25 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 31 Jul 2024 04:55:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= secure.kjonigsen.net; h=cc:cc: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=1722416125; x=1722502525; bh=nVKEAQNYBaY4kafUFwGoMg+TGQpTqX9X6vy2+ihdXhw=; b= 19ZGKGQubkrUP1c6spSBuZajgL21LizIWkZIUcVU8J1mxqksTmwD+/6OBo7sKR2X gMx0Ap53sACOSG/HirykFAieXWf8eFzkwIDqigXghgnJGuUXdeEp0hb1hqg99hfO 54M5Oc2k80rVKcQkyhshAtp/wgYA77GzJ+tYRAvD+fkXzYBUdxuLHgSii/2N891R T+F/Sgc4/ux8wym2pYaF1RNp9xoX2BQw4if5dBR9nSv+eaJZpxk5aAOrXwGWn0kJ q0DXlhw8b9g58t/N6OiTaRH7Sx7HI9myUVpeTcxnxWpuF41YkZia2fqnMRwPRVtm OClrTb6WYfPUtSSf3lPdLw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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=1722416125; x=1722502525; bh=nVKEAQNYBaY4kafUFwGoMg+TGQpT qX9X6vy2+ihdXhw=; b=GjgE/WMoAGbaeAgRpmvCZMk59bZ7dUBBpKbaXv5piNsv q9jAnAkPJESXe+0BVi+AyN44ZGjzkcPdcMbR8jeQIl679uw1qgjmg2rfcjoRSrfE s5ue6ZKro6hy4lpxTki8H0ZsXTOJfL5JnW/M2g0dNE5T1J+HodzljWXFPeD7MAkE 6LIDZ8QCfgWurOrAb4RsD/wAt0oLGjPgvuN3WDsqSaBnL8Uxm5/dRXRHQJbd9oCQ ckXUEAlHage7umoUK+NnyTpyXmIb3ZrgOO0XSi/IY8hlVQhvfiCpPSBE7pELJNJy STKf6p+vnXdJJKyo0Ok1thMR5YE6UruvcGcONrIYCQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhkfgtggfuffgjvefvfhfosegrtdhmrehhtddvnecuhfhrohhmpeflohhsthgv ihhnucfmjhppnhhighhsvghnuceojhhoshhtvghinhesshgvtghurhgvrdhkjhhonhhigh hsvghnrdhnvghtqeenucggtffrrghtthgvrhhnpeeggeffveeigeegudejhefhfedtgedt udegjeeuvdetueejuedtkeeijeeijeetleenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehjohhsthgvihhnsehsvggtuhhrvgdrkhhjohhnihhg shgvnhdrnhgvthdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ib2f84088:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 31 Jul 2024 04:55:23 -0400 (EDT) In-Reply-To: <8634nv2tcq.fsf@gnu.org> X-Mailer: Apple Mail (2.3774.500.171.1.1) 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:289578 Archived-At: --Apple-Mail=_6701E944-F619-4FF0-9B13-B7EBAE0B36FD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 27 Jul 2024, at 09:21, Eli Zaretskii wrote: >=20 >> Cc: 72184@debbugs.gnu.org >> Date: Sat, 20 Jul 2024 03:22:47 +0300 >> From: Dmitry Gutov >>=20 >> Right, we normally handle automatic indentation using=20 >> electric-indent-mode (which is on by default). >>=20 >> If RET behaves incorrectly in typescript-ts-mode somehow, more = details=20 >> should be provided. >=20 > Jostein, could you please respond, so that we could make progress > here? >=20 > Thanks. 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. 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) })) =20 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? -- Jostein= --Apple-Mail=_6701E944-F619-4FF0-9B13-B7EBAE0B36FD Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii


On 27 Jul 2024, at 09:21, Eli = Zaretskii <eliz@gnu.org> wrote:

Cc: 72184@debbugs.gnu.org
Date: Sat, 20 Jul 2024 = 03:22:47 +0300
From: Dmitry Gutov = <dmitry@gutov.dev>

Right, we normally handle automatic = indentation using
electric-indent-mode (which is on by = default).

If RET behaves incorrectly in typescript-ts-mode = somehow, more details
should be = provided.

Jostein, could you please respond, so that = we could make = progress
here?

Thanks.


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.

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?

--
Jostein
= --Apple-Mail=_6701E944-F619-4FF0-9B13-B7EBAE0B36FD--