unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dmitry@gutov.dev>
To: "Jostein Kjønigsen" <jostein@secure.kjonigsen.net>,
	"Eli Zaretskii" <eliz@gnu.org>
Cc: Yuan Fu <casouri@gmail.com>,
	acorallo@gnu.org, Theodor Thornhill <theo@thornhill.no>,
	72184@debbugs.gnu.org
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	[thread overview]
Message-ID: <d2f34f69-bb9f-4c6f-8927-9bae0128287f@gutov.dev> (raw)
In-Reply-To: <5088180E-50DC-4374-B7F3-78DA6244291C@secure.kjonigsen.net>

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.





  reply	other threads:[~2024-08-01  0:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-18 21:05 bug#72184: 31.0.50; typescript-ts-mode does not bind RET to newline-and-indent Jostein Kjønigsen
2024-07-18 21:30 ` Andrea Corallo
2024-07-20  0:22   ` Dmitry Gutov
2024-07-27  7:21     ` Eli Zaretskii
2024-07-27 11:50       ` Jostein Kjønigsen
2024-07-27 12:20         ` Eli Zaretskii
2024-07-31  8:55       ` Jostein Kjønigsen
2024-08-01  0:42         ` Dmitry Gutov [this message]
2024-08-15 10:03           ` Jostein Kjønigsen
2024-08-17 10:11             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d2f34f69-bb9f-4c6f-8927-9bae0128287f@gutov.dev \
    --to=dmitry@gutov.dev \
    --cc=72184@debbugs.gnu.org \
    --cc=acorallo@gnu.org \
    --cc=casouri@gmail.com \
    --cc=eliz@gnu.org \
    --cc=jostein@secure.kjonigsen.net \
    --cc=theo@thornhill.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).