unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Aaron Jensen <aaronjensen@gmail.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 61017@debbugs.gnu.org
Subject: bug#61017: 29.0.60; ruby-ts-mode indents class between two lines incorrectly
Date: Tue, 24 Jan 2023 19:45:13 -0500	[thread overview]
Message-ID: <CAHyO48y7jG7QLrk3NekuPaLDYVJFV9Az9FhB0-Zh-cyYNbpB1Q@mail.gmail.com> (raw)
In-Reply-To: <dac5d62f-f52a-49fe-1f35-c1ccbfc57a6d@yandex.ru>

On Tue, Jan 24, 2023 at 1:53 PM Dmitry Gutov <dgutov@yandex.ru> wrote:
>
> On 24/01/2023 16:17, Aaron Jensen wrote:
> > On Mon, Jan 23, 2023 at 4:28 PM Dmitry Gutov <dgutov@yandex.ru> wrote:
> >>
> >> Hi!
> >>
> >> On 23/01/2023 06:33, Aaron Jensen wrote:
> >>>
> >>> Start with a buffer in ruby-ts-mode like:
> >>>
> >>> a
> >>>
> >>> b
> >>>
> >>> Between the two lines, type "class Foo", then press enter
> >>>
> >>> You should get this:
> >>>
> >>> a
> >>>
> >>>     class Foo
> >>>
> >>> b
> >>>
> >>> But this is expected:
> >>>
> >>> a
> >>>
> >>> class Foo
> >>>
> >>> b
> >>>
> >>> Note that reindenting after adding the "end" will indent correctly, so
> >>> it's only an issue with electric indent
> >>
> >> Thanks for the report, the problem here is that such examples parse into
> >> a malformed syntax tree:
> >>
> >>     (program (identifier)
> >>      (ERROR class (constant) (identifier)))
> >>
> >> Another example would be:
> >>
> >>     class C
> >>       def foo
> >>
> >> which parses as
> >>
> >>     (ERROR class (constant) def (identifier))
> >>
> >> We can try to anticipate such cases and infer the implied structure
> >> somehow, or just disable indentation for specific cases. See the
> >> attached patch for the latter.
> >>
> >> Is it enough of an improvement?
> >
> > That seems to make indentation after an open def not happen:
> >
> > def foo
> > bar
> > end
>
> Not sure what you mean. Is that an example with an "open def"? "end"
> seems to be closing it. In the final state, it indents correctly here.

Sorry, that's what I meant. If I do type exactly that and do not
reindent, I end up with that though (closing with the end does not
cause the previous line to reindent)

>
> > I applied the patch manually though, so maybe you can confirm that you
> > see the same thing?
>
> If I have a buffer with just the first line:
>
>    def foo
>
> then it indeed doesn't indent. But I think that happens with or without
> this patch?
>
> It's a slightly different problem: the grammar parses this code example
> without ERROR nodes, like a full method, for some reason:
>
>    (program
>     (method def body: (identifier) end))
>
> And the end position of the "virtual" end node stays at the previous
> line, so our code doesn't know it's inside the method.
>
> I suppose we could add some tricky predicate like (is the previous node
> a method with an "end" child that is 0 characters long), but the grammar
> might change (we should look for any previous reported issues about this
> behavior, or maybe ones that resulted in it), and it only happen this
> way when there is nothing after "def xyz" in the buffer.

I wonder if this is mistaken handling of endless methods? I can't
think of a reason that it would parse like that. Should that be
reported upstream?

> Because in the more common case, like
>
>    class C
>      def foo
>        |
>    end
>
> the last "end" is parsed like the closer for the method, the method node
> spans until it, and the line with "|" indents correctly.
>
> WDYT?





  reply	other threads:[~2023-01-25  0:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23  4:33 bug#61017: 29.0.60; ruby-ts-mode indents class between two lines incorrectly Aaron Jensen
2023-01-23 21:28 ` Dmitry Gutov
2023-01-24 14:17   ` Aaron Jensen
2023-01-24 18:53     ` Dmitry Gutov
2023-01-25  0:45       ` Aaron Jensen [this message]
2023-01-25  4:00         ` Dmitry Gutov
2023-01-25 14:22           ` Aaron Jensen
2023-01-25 15:23             ` Dmitry Gutov

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=CAHyO48y7jG7QLrk3NekuPaLDYVJFV9Az9FhB0-Zh-cyYNbpB1Q@mail.gmail.com \
    --to=aaronjensen@gmail.com \
    --cc=61017@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /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).