GNU bug report logs - #77727
tsx-ts-mode: fill-paragraph doesn't work for doc-comments

Previous Next

Package: emacs;

Reported by: Konstantin Kharlamov <Hi-Angel <at> yandex.ru>

Date: Fri, 11 Apr 2025 08:12:02 UTC

Severity: normal

Done: Yuan Fu <casouri <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Yuan Fu <casouri <at> gmail.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#77727: closed (tsx-ts-mode: fill-paragraph doesn't work for
 doc-comments)
Date: Fri, 18 Apr 2025 23:36:03 +0000
[Message part 1 (text/plain, inline)]
Your message dated Fri, 18 Apr 2025 16:35:13 -0700
with message-id <796789BF-C2C8-47F4-AE05-826373DF90DB <at> gmail.com>
and subject line Re: [PATCH] Limit rust-ts-specific comment-start check to rust-ts (bug#77727)
has caused the debbugs.gnu.org bug report #77727,
regarding tsx-ts-mode: fill-paragraph doesn't work for doc-comments
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
77727: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=77727
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Konstantin Kharlamov <Hi-Angel <at> yandex.ru>
To: bug-gnu-emacs <at> gnu.org
Subject: tsx-ts-mode: fill-paragraph doesn't work for doc-comments
Date: Fri, 11 Apr 2025 11:10:34 +0300
Steps to reproduce:

1. Open `test.tsx` with the following content:

    // File description
    /**
     * Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis.
     */
2. Try to "fill" the Lorem ipsum text.

Result: nothing changes, the text doesn't get "filled".

---------

I dug into it, the bug resides in the following condition in
`c-ts-common--fill-paragraph`:

                …
                ;; In rust, NODE will be the body of a comment, and the
                ;; parent will be the whole comment.
                (if-let* ((start (treesit-node-start
                                  (treesit-node-parent node))))
                    (save-excursion
                      (goto-char start)
                      (looking-at "//"))))
                …

The problem is that "(treesit-node-start (treesit-node-parent node))" returns 1.
That happens disregarding the amount of code between the "// File description"
line and where "/* Lorem ipsum…" is. In the actual code there's 51 lines in
between.

Why treesit-node-start does that I don't know, so I decided to report it.


[Message part 3 (message/rfc822, inline)]
From: Yuan Fu <casouri <at> gmail.com>
To: Konstantin Kharlamov <Hi-Angel <at> yandex.ru>
Cc: 77727-done <at> debbugs.gnu.org
Subject: Re: [PATCH] Limit rust-ts-specific comment-start check to rust-ts
 (bug#77727)
Date: Fri, 18 Apr 2025 16:35:13 -0700

> On Apr 18, 2025, at 2:48 AM, Konstantin Kharlamov <Hi-Angel <at> yandex.ru> wrote:
> 
> On Wed, 2025-04-16 at 22:58 -0700, Yuan Fu wrote:
>> 
>> 
>>> On Apr 11, 2025, at 4:51 AM, Konstantin Kharlamov
>>> <Hi-Angel <at> yandex.ru> wrote:
>>> 
>>> On Fri, 2025-04-11 at 11:34 +0300, Konstantin Kharlamov wrote:
>>>> CC: Yuan Fu as the author of the code in question.
>>>> 
>>>> What happens in the code makes sense: since the comment resides
>>>> at
>>>> top-
>>>> level, the parent of any top-level statement (returned by
>>>> (treesit-
>>>> node-parent node)) is, well, beginning of a buffer.
>>>> 
>>>> So the question is, why the check works that way.
>>> 
>>> Please see the attached patch, it'd seem this is exactly the fix
>>> that's
>>> expected here. Basically, the problematic check is specific to Rust
>>> treesitter mode, so shouldn't be executed in other languages. The
>>> patch
>>> factors out the entire check to a separate function and adds
>>> additional
>>> condition of (eq major-mode 'rust-ts-mode).
>>> 
>>> Tested in tsx-ts-mode, it fixes the problem.
>>> <1.patch>
>> 
>> Thanks! Your analysis is correct. But I don’t want to hard-code rust-
>> ts-mode in the function, since modes with other names can very well
>> use rust parser. I pushed 9d43715baa5 that operates in the similar
>> vein as your patch. Instead of checking for the current major mode, I
>> tighten the condition by adding an additional check that ensure the
>> parent node is a comment node. So now if the parent node is the root
>> node (as in your initial example), the condition should fail. Please
>> see if it fixes your problem.
>> 
>> Yuan
> 
> Thank you, I confirm the problem is fixed, so bug can be closed.

Great, closing the report.

Yuan

This bug report was last modified 31 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.