GNU bug report logs - #70345
[PATCH] 29.1.50; csharp-ts-mode indentation of if statements with single-statement body

Previous Next

Package: emacs;

Reported by: Jacob Leeming <jacobtophatleeming <at> gmail.com>

Date: Thu, 11 Apr 2024 20:33:03 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 70345 in the body.
You can then email your comments to 70345 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Thu, 11 Apr 2024 20:33:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jacob Leeming <jacobtophatleeming <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 11 Apr 2024 20:33:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jacob Leeming <jacobtophatleeming <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] 29.1.50; csharp-ts-mode indentation of if statements with
 single-statement body
Date: Thu, 11 Apr 2024 21:32:02 +0100
Hi all,

From emacs -Q:

Evaluate this elisp to set up treesitter for csharp:

(setq treesit-language-source-alist '((c-sharp
"https://github.com/tree-sitter/tree-sitter-c-sharp" "master" "src"))
      treesit-load-name-override-list '((c-sharp
"libtree-sitter-csharp" "tree_sitter_c_sharp"))
      major-mode-remap-alist '((csharp-mode . csharp-ts-mode)))

Insert the following text into a csharp-ts-mode buffer:

if (true)
var x = 2;

Try to indent the variable declaration of the function with
indent-for-tab-command. Nothing will happen. I'd expect to see this:

if (true)
    var x = 2;

This issue can be fixed with the following patch:

diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 53c52e6..1a7d535 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -678,7 +678,8 @@ csharp-ts-mode--indent-rules
      ((parent-is "binary_expression") parent 0)
      ((parent-is "block") parent-bol csharp-ts-mode-indent-offset)
      ((parent-is "local_function_statement") parent-bol 0)
-     ((parent-is "if_statement") parent-bol 0)
+     ((match "block" "if_statement") parent-bol 0)
+     ((parent-is "if_statement") parent-bol csharp-ts-mode-indent-offset)
      ((parent-is "for_statement") parent-bol 0)
      ((parent-is "for_each_statement") parent-bol 0)
      ((parent-is "while_statement") parent-bol 0)

Cheers,
Jacob




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Fri, 12 Apr 2024 05:46:13 GMT) Full text and rfc822 format available.

Message #8 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Theodor Thornhill <theo <at> thornhill.no>, Yuan Fu <casouri <at> gmail.com>
Cc: 70345 <at> debbugs.gnu.org, Jacob Leeming <jacobtophatleeming <at> gmail.com>
Subject: Re: bug#70345: [PATCH] 29.1.50;
 csharp-ts-mode indentation of if statements with single-statement body
Date: Fri, 12 Apr 2024 08:45:19 +0300
> From: Jacob Leeming <jacobtophatleeming <at> gmail.com>
> Date: Thu, 11 Apr 2024 21:32:02 +0100
> 
> Hi all,
> 
> >From emacs -Q:
> 
> Evaluate this elisp to set up treesitter for csharp:
> 
> (setq treesit-language-source-alist '((c-sharp
> "https://github.com/tree-sitter/tree-sitter-c-sharp" "master" "src"))
>       treesit-load-name-override-list '((c-sharp
> "libtree-sitter-csharp" "tree_sitter_c_sharp"))
>       major-mode-remap-alist '((csharp-mode . csharp-ts-mode)))
> 
> Insert the following text into a csharp-ts-mode buffer:
> 
> if (true)
> var x = 2;
> 
> Try to indent the variable declaration of the function with
> indent-for-tab-command. Nothing will happen. I'd expect to see this:
> 
> if (true)
>     var x = 2;
> 
> This issue can be fixed with the following patch:
> 
> diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
> index 53c52e6..1a7d535 100644
> --- a/lisp/progmodes/csharp-mode.el
> +++ b/lisp/progmodes/csharp-mode.el
> @@ -678,7 +678,8 @@ csharp-ts-mode--indent-rules
>       ((parent-is "binary_expression") parent 0)
>       ((parent-is "block") parent-bol csharp-ts-mode-indent-offset)
>       ((parent-is "local_function_statement") parent-bol 0)
> -     ((parent-is "if_statement") parent-bol 0)
> +     ((match "block" "if_statement") parent-bol 0)
> +     ((parent-is "if_statement") parent-bol csharp-ts-mode-indent-offset)
>       ((parent-is "for_statement") parent-bol 0)
>       ((parent-is "for_each_statement") parent-bol 0)
>       ((parent-is "while_statement") parent-bol 0)

Theo and Yuan, any comments?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Sun, 14 Apr 2024 23:04:03 GMT) Full text and rfc822 format available.

Message #11 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70345 <at> debbugs.gnu.org, theo <at> thornhill.no, jacobtophatleeming <at> gmail.com
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if 
 statements with single-statement body
Date: Sun, 14 Apr 2024 16:02:50 -0700
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Jacob Leeming <jacobtophatleeming <at> gmail.com>
>> Date: Thu, 11 Apr 2024 21:32:02 +0100
>> 
>> Hi all,
>> 
>> >From emacs -Q:
>> 
>> Evaluate this elisp to set up treesitter for csharp:
>> 
>> (setq treesit-language-source-alist '((c-sharp
>> "https://github.com/tree-sitter/tree-sitter-c-sharp" "master" "src"))
>>       treesit-load-name-override-list '((c-sharp
>> "libtree-sitter-csharp" "tree_sitter_c_sharp"))
>>       major-mode-remap-alist '((csharp-mode . csharp-ts-mode)))
>> 
>> Insert the following text into a csharp-ts-mode buffer:
>> 
>> if (true)
>> var x = 2;
>> 
>> Try to indent the variable declaration of the function with
>> indent-for-tab-command. Nothing will happen. I'd expect to see this:
>> 
>> if (true)
>>     var x = 2;
>> 
>> This issue can be fixed with the following patch:
>> 
>> diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
>> index 53c52e6..1a7d535 100644
>> --- a/lisp/progmodes/csharp-mode.el
>> +++ b/lisp/progmodes/csharp-mode.el
>> @@ -678,7 +678,8 @@ csharp-ts-mode--indent-rules
>>       ((parent-is "binary_expression") parent 0)
>>       ((parent-is "block") parent-bol csharp-ts-mode-indent-offset)
>>       ((parent-is "local_function_statement") parent-bol 0)
>> -     ((parent-is "if_statement") parent-bol 0)
>> +     ((match "block" "if_statement") parent-bol 0)
>> +     ((parent-is "if_statement") parent-bol csharp-ts-mode-indent-offset)
>>       ((parent-is "for_statement") parent-bol 0)
>>       ((parent-is "for_each_statement") parent-bol 0)
>>       ((parent-is "while_statement") parent-bol 0)
>
> Theo and Yuan, any comments?

If Theo is too busy I can take a look, but I don’t really know
csharp-ts-mode too well.

Yuan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Mon, 15 Apr 2024 04:58:04 GMT) Full text and rfc822 format available.

Message #14 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Theodor Thornhill <theo <at> thornhill.no>
To: Yuan Fu <casouri <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 70345 <at> debbugs.gnu.org,
 jacobtophatleeming <at> gmail.com
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if 
 statements with single-statement body
Date: Mon, 15 Apr 2024 06:56:52 +0200
[Message part 1 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Mon, 15 Apr 2024 19:02:05 GMT) Full text and rfc822 format available.

Message #17 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Theodor Thornhill <theo <at> thornhill.no>
To: Jacob Leeming <jacobtophatleeming <at> gmail.com>
Cc: 70345 <at> debbugs.gnu.org
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if
 statements with single-statement body
Date: Mon, 15 Apr 2024 21:01:27 +0200
> Hi all,
>

Hi, Jacob!

>>From emacs -Q:
>
> Evaluate this elisp to set up treesitter for csharp:
>
> (setq treesit-language-source-alist '((c-sharp
> "https://github.com/tree-sitter/tree-sitter-c-sharp" "master" "src"))
>       treesit-load-name-override-list '((c-sharp
> "libtree-sitter-csharp" "tree_sitter_c_sharp"))
>       major-mode-remap-alist '((csharp-mode . csharp-ts-mode)))
>
> Insert the following text into a csharp-ts-mode buffer:
>
> if (true)
> var x = 2;
>
> Try to indent the variable declaration of the function with
> indent-for-tab-command. Nothing will happen. I'd expect to see this:
>
> if (true)
>     var x = 2;
>
> This issue can be fixed with the following patch:
>
> diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
> index 53c52e6..1a7d535 100644
> --- a/lisp/progmodes/csharp-mode.el
> +++ b/lisp/progmodes/csharp-mode.el
> @@ -678,7 +678,8 @@ csharp-ts-mode--indent-rules
>       ((parent-is "binary_expression") parent 0)
>       ((parent-is "block") parent-bol csharp-ts-mode-indent-offset)
>       ((parent-is "local_function_statement") parent-bol 0)
> -     ((parent-is "if_statement") parent-bol 0)
> +     ((match "block" "if_statement") parent-bol 0)
> +     ((parent-is "if_statement") parent-bol csharp-ts-mode-indent-offset)
>       ((parent-is "for_statement") parent-bol 0)
>       ((parent-is "for_each_statement") parent-bol 0)
>       ((parent-is "while_statement") parent-bol 0)
>

Looks good to me. Are you willing to pack this up with a nice test
confirming the behavior?

All the best,
Theo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Mon, 15 Apr 2024 23:41:01 GMT) Full text and rfc822 format available.

Message #20 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Jacob Leeming <jacobtophatleeming <at> gmail.com>
To: Theodor Thornhill <theo <at> thornhill.no>
Cc: 70345 <at> debbugs.gnu.org
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if
 statements with single-statement body
Date: Mon, 15 Apr 2024 22:38:00 +0100
Theodor Thornhill <theo <at> thornhill.no> writes:

>> Hi all,
>>
>
> Hi, Jacob!
>
>>From emacs -Q:
>>
>> Evaluate this elisp to set up treesitter for csharp:
>>
>> (setq treesit-language-source-alist '((c-sharp
>> "https://github.com/tree-sitter/tree-sitter-c-sharp" "master" "src"))
>>       treesit-load-name-override-list '((c-sharp
>> "libtree-sitter-csharp" "tree_sitter_c_sharp"))
>>       major-mode-remap-alist '((csharp-mode . csharp-ts-mode)))
>>
>> Insert the following text into a csharp-ts-mode buffer:
>>
>> if (true)
>> var x = 2;
>>
>> Try to indent the variable declaration of the function with
>> indent-for-tab-command. Nothing will happen. I'd expect to see this:
>>
>> if (true)
>>     var x = 2;
>>
>> This issue can be fixed with the following patch:
>>
>> diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
>> index 53c52e6..1a7d535 100644
>> --- a/lisp/progmodes/csharp-mode.el
>> +++ b/lisp/progmodes/csharp-mode.el
>> @@ -678,7 +678,8 @@ csharp-ts-mode--indent-rules
>>       ((parent-is "binary_expression") parent 0)
>>       ((parent-is "block") parent-bol csharp-ts-mode-indent-offset)
>>       ((parent-is "local_function_statement") parent-bol 0)
>> -     ((parent-is "if_statement") parent-bol 0)
>> +     ((match "block" "if_statement") parent-bol 0)
>> +     ((parent-is "if_statement") parent-bol csharp-ts-mode-indent-offset)
>>       ((parent-is "for_statement") parent-bol 0)
>>       ((parent-is "for_each_statement") parent-bol 0)
>>       ((parent-is "while_statement") parent-bol 0)
>>
>
> Looks good to me. Are you willing to pack this up with a nice test
> confirming the behavior?
>
> All the best,
> Theo

I'm willing, where can I find other tests for csharp-ts-mode? Had a
quick look round the emacs repo but could not find any.

Cheers,
Jacob




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Tue, 16 Apr 2024 00:28:05 GMT) Full text and rfc822 format available.

Message #23 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Jacob Leeming <jacobtophatleeming <at> gmail.com>,
 Theodor Thornhill <theo <at> thornhill.no>
Cc: 70345 <at> debbugs.gnu.org
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if
 statements with single-statement body
Date: Tue, 16 Apr 2024 03:27:33 +0300
On 16/04/2024 00:38, Jacob Leeming wrote:
> I'm willing, where can I find other tests for csharp-ts-mode? Had a
> quick look round the emacs repo but could not find any.

Check out

test/lisp/progmodes/csharp-mode-resources/indent.erts
and
test/lisp/progmodes/csharp-mode-tests.el

These are for csharp-mode (non tree-sitter version), so you'll basically 
need to make a copy of the latter to run the counterpart for the former.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Mon, 22 Apr 2024 08:51:03 GMT) Full text and rfc822 format available.

Message #26 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Jacob Leeming <jacobtophatleeming <at> gmail.com>
To: Theodor Thornhill <theo <at> thornhill.no>, Dmitry Gutov <dmitry <at> gutov.dev>
Cc: 70345 <at> debbugs.gnu.org, Jacob Leeming <jacobtophatleeming <at> gmail.com>
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if
 statements with single-statement body
Date: Mon, 22 Apr 2024 09:50:23 +0100
[Message part 1 (text/plain, inline)]
> Theodor Thornhill <theo <at> thornhill.no> writes:

>> Hi all,
>>
>
> Hi, Jacob!
>
>>>From emacs -Q:
>>
>> Evaluate this elisp to set up treesitter for csharp:
>>
>> (setq treesit-language-source-alist '((c-sharp
>> "https://github.com/tree-sitter/tree-sitter-c-sharp" "master" "src"))
>>       treesit-load-name-override-list '((c-sharp
>> "libtree-sitter-csharp" "tree_sitter_c_sharp"))
>>       major-mode-remap-alist '((csharp-mode . csharp-ts-mode)))
>>
>> Insert the following text into a csharp-ts-mode buffer:
>>
>> if (true)
>> var x = 2;
>>
>> Try to indent the variable declaration of the function with
>> indent-for-tab-command. Nothing will happen. I'd expect to see this:
>>
>> if (true)
>>     var x = 2;
>>
>> This issue can be fixed with the following patch:
>>
>> diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
>> index 53c52e6..1a7d535 100644
>> --- a/lisp/progmodes/csharp-mode.el
>> +++ b/lisp/progmodes/csharp-mode.el
>> @@ -678,7 +678,8 @@ csharp-ts-mode--indent-rules
>>       ((parent-is "binary_expression") parent 0)
>>       ((parent-is "block") parent-bol csharp-ts-mode-indent-offset)
>>       ((parent-is "local_function_statement") parent-bol 0)
>> -     ((parent-is "if_statement") parent-bol 0)
>> +     ((match "block" "if_statement") parent-bol 0)
>> +     ((parent-is "if_statement") parent-bol csharp-ts-mode-indent-offset)
>>       ((parent-is "for_statement") parent-bol 0)
>>       ((parent-is "for_each_statement") parent-bol 0)
>>       ((parent-is "while_statement") parent-bol 0)
>>
>
> Looks good to me. Are you willing to pack this up with a nice test
> confirming the behavior?
>
> All the best,
> Theo

Thanks all,

Discovered we had a similar issue for else blocks. Wrote a test that
covers both cases.

See the attached diff which contains my changes to the indent rules and
the test.

Cheers,
Jacob

[0001-indent-single-statement-if-in-csharp-ts-mode.patch (text/x-diff, attachment)]

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Thu, 25 Apr 2024 16:05:04 GMT) Full text and rfc822 format available.

Notification sent to Jacob Leeming <jacobtophatleeming <at> gmail.com>:
bug acknowledged by developer. (Thu, 25 Apr 2024 16:05:04 GMT) Full text and rfc822 format available.

Message #31 received at 70345-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jacob Leeming <jacobtophatleeming <at> gmail.com>
Cc: dmitry <at> gutov.dev, 70345-done <at> debbugs.gnu.org, theo <at> thornhill.no
Subject: Re: bug#70345: [PATCH] 29.1.50;
 csharp-ts-mode indentation of if statements with single-statement body
Date: Thu, 25 Apr 2024 19:04:14 +0300
> Cc: 70345 <at> debbugs.gnu.org, Jacob Leeming <jacobtophatleeming <at> gmail.com>
> From: Jacob Leeming <jacobtophatleeming <at> gmail.com>
> Date: Mon, 22 Apr 2024 09:50:23 +0100
> 
> > Looks good to me. Are you willing to pack this up with a nice test
> > confirming the behavior?
> >
> > All the best,
> > Theo
> 
> Thanks all,
> 
> Discovered we had a similar issue for else blocks. Wrote a test that
> covers both cases.
> 
> See the attached diff which contains my changes to the indent rules and
> the test.

Thanks, I installed this on the emacs-29 branch.  (The test you added
should have been added to csharp-mode-tests.el, since our test files
follow the names of the implementation files, and csharp-ts-mode is
implemented in csharp-mode.el.  I fixed that.)

With this changeset you have exhausted the amount of changes that we
can accept from you without copyright assignment.  Would you like to
start the paperwork of assigning the copyright at this time, so that
we could accept your contributions in the future without limitations?
If yes, I will send you the form to fill and the instructions to send
the form.

I'm closing this bug.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Fri, 26 Apr 2024 13:55:13 GMT) Full text and rfc822 format available.

Message #34 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Jacob Leeming <jacobtophatleeming <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70345 <at> debbugs.gnu.org
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if
 statements with single-statement body
Date: Fri, 26 Apr 2024 14:53:36 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

>> Cc: 70345 <at> debbugs.gnu.org, Jacob Leeming <jacobtophatleeming <at> gmail.com>
>> From: Jacob Leeming <jacobtophatleeming <at> gmail.com>
>> Date: Mon, 22 Apr 2024 09:50:23 +0100
>> 
>> > Looks good to me. Are you willing to pack this up with a nice test
>> > confirming the behavior?
>> >
>> > All the best,
>> > Theo
>> 
>> Thanks all,
>> 
>> Discovered we had a similar issue for else blocks. Wrote a test that
>> covers both cases.
>> 
>> See the attached diff which contains my changes to the indent rules and
>> the test.
>
> Thanks, I installed this on the emacs-29 branch.  (The test you added
> should have been added to csharp-mode-tests.el, since our test files
> follow the names of the implementation files, and csharp-ts-mode is
> implemented in csharp-mode.el.  I fixed that.)
>
> With this changeset you have exhausted the amount of changes that we
> can accept from you without copyright assignment.  Would you like to
> start the paperwork of assigning the copyright at this time, so that
> we could accept your contributions in the future without limitations?
> If yes, I will send you the form to fill and the instructions to send
> the form.
>
> I'm closing this bug.

Thanks Eli,

Please send the paperwork! I'll get it filled in and sent off when
possible. If I have future questions about the paperwork, is it best to
use the emacs devel mailing list?

Cheers,
Jacob




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Fri, 26 Apr 2024 15:25:02 GMT) Full text and rfc822 format available.

Message #37 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jacob Leeming <jacobtophatleeming <at> gmail.com>
Cc: 70345 <at> debbugs.gnu.org
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if
 statements with single-statement body
Date: Fri, 26 Apr 2024 18:24:07 +0300
> From: Jacob Leeming <jacobtophatleeming <at> gmail.com>
> Cc: 70345 <at> debbugs.gnu.org
> Date: Fri, 26 Apr 2024 14:53:36 +0100
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > With this changeset you have exhausted the amount of changes that we
> > can accept from you without copyright assignment.  Would you like to
> > start the paperwork of assigning the copyright at this time, so that
> > we could accept your contributions in the future without limitations?
> > If yes, I will send you the form to fill and the instructions to send
> > the form.
> >
> > I'm closing this bug.
> 
> Thanks Eli,
> 
> Please send the paperwork! I'll get it filled in and sent off when
> possible.

Thanks, form sent off-list.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Sat, 27 Apr 2024 15:15:01 GMT) Full text and rfc822 format available.

Message #40 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: john muhl <jm <at> pub.pink>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: dmitry <at> gutov.dev, 70345 <at> debbugs.gnu.org, theo <at> thornhill.no,
 Jacob Leeming <jacobtophatleeming <at> gmail.com>
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if
 statements with single-statement body
Date: Sat, 27 Apr 2024 08:10:47 -0500
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:

>> Cc: 70345 <at> debbugs.gnu.org, Jacob Leeming <jacobtophatleeming <at> gmail.com>
>> From: Jacob Leeming <jacobtophatleeming <at> gmail.com>
>> Date: Mon, 22 Apr 2024 09:50:23 +0100
>> 
>> > Looks good to me. Are you willing to pack this up with a nice test
>> > confirming the behavior?
>> >
>> > All the best,
>> > Theo
>> 
>> Thanks all,
>> 
>> Discovered we had a similar issue for else blocks. Wrote a test that
>> covers both cases.
>> 
>> See the attached diff which contains my changes to the indent rules and
>> the test.
>
> Thanks, I installed this on the emacs-29 branch.  (The test you added
> should have been added to csharp-mode-tests.el, since our test files
> follow the names of the implementation files, and csharp-ts-mode is
> implemented in csharp-mode.el.  I fixed that.)

The test should check that the c-sharp grammar is available so
that it gets marked as skipped instead of failed.

[0001-Skip-csharp-ts-mode-test-if-grammar-is-missing.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Sat, 27 Apr 2024 15:43:01 GMT) Full text and rfc822 format available.

Message #43 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: john muhl <jm <at> pub.pink>
Cc: dmitry <at> gutov.dev, 70345 <at> debbugs.gnu.org, theo <at> thornhill.no,
 jacobtophatleeming <at> gmail.com
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if
 statements with single-statement body
Date: Sat, 27 Apr 2024 18:41:59 +0300
> From: john muhl <jm <at> pub.pink>
> Cc: Jacob Leeming <jacobtophatleeming <at> gmail.com>, dmitry <at> gutov.dev,
>  70345 <at> debbugs.gnu.org, theo <at> thornhill.no
> Date: Sat, 27 Apr 2024 08:10:47 -0500
> 
> The test should check that the c-sharp grammar is available so
> that it gets marked as skipped instead of failed.
> 
> >From 068cad8612c31cea41f0cc21a865efe0785d4e7a Mon Sep 17 00:00:00 2001
> From: john muhl <jm <at> pub.pink>
> Date: Sat, 27 Apr 2024 09:55:42 -0500
> Subject: [PATCH] ; Skip 'csharp-ts-mode' test if grammar is missing
> 
> * test/lisp/progmodes/csharp-mode-tests.el
> (csharp-ts-mode-test-indentation): Skip test instead of failing.
> ---
>  test/lisp/progmodes/csharp-mode-tests.el | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/test/lisp/progmodes/csharp-mode-tests.el b/test/lisp/progmodes/csharp-mode-tests.el
> index 2878fa601f2..b3c57a7026b 100644
> --- a/test/lisp/progmodes/csharp-mode-tests.el
> +++ b/test/lisp/progmodes/csharp-mode-tests.el
> @@ -27,6 +27,7 @@ csharp-mode-test-indentation
>    (ert-test-erts-file (ert-resource-file "indent.erts")))
>  
>  (ert-deftest csharp-ts-mode-test-indentation ()
> +  (skip-unless (treesit-ready-p 'c-sharp))
>    (ert-test-erts-file (ert-resource-file "indent-ts.erts")))

Thanks, but shouldn't we invoke treesit-ready-p with second argument
non-nil?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Sat, 27 Apr 2024 17:18:02 GMT) Full text and rfc822 format available.

Message #46 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: john muhl <jm <at> pub.pink>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: dmitry <at> gutov.dev, 70345 <at> debbugs.gnu.org, theo <at> thornhill.no,
 jacobtophatleeming <at> gmail.com
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if
 statements with single-statement body
Date: Sat, 27 Apr 2024 12:13:12 -0500
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: john muhl <jm <at> pub.pink>
>> Cc: Jacob Leeming <jacobtophatleeming <at> gmail.com>, dmitry <at> gutov.dev,
>>  70345 <at> debbugs.gnu.org, theo <at> thornhill.no
>> Date: Sat, 27 Apr 2024 08:10:47 -0500
>> 
>> The test should check that the c-sharp grammar is available so
>> that it gets marked as skipped instead of failed.
>> 
>> >From 068cad8612c31cea41f0cc21a865efe0785d4e7a Mon Sep 17 00:00:00 2001
>> From: john muhl <jm <at> pub.pink>
>> Date: Sat, 27 Apr 2024 09:55:42 -0500
>> Subject: [PATCH] ; Skip 'csharp-ts-mode' test if grammar is missing
>> 
>> * test/lisp/progmodes/csharp-mode-tests.el
>> (csharp-ts-mode-test-indentation): Skip test instead of failing.
>> ---
>>  test/lisp/progmodes/csharp-mode-tests.el | 1 +
>>  1 file changed, 1 insertion(+)
>> 
>> diff --git a/test/lisp/progmodes/csharp-mode-tests.el b/test/lisp/progmodes/csharp-mode-tests.el
>> index 2878fa601f2..b3c57a7026b 100644
>> --- a/test/lisp/progmodes/csharp-mode-tests.el
>> +++ b/test/lisp/progmodes/csharp-mode-tests.el
>> @@ -27,6 +27,7 @@ csharp-mode-test-indentation
>>    (ert-test-erts-file (ert-resource-file "indent.erts")))
>>  
>>  (ert-deftest csharp-ts-mode-test-indentation ()
>> +  (skip-unless (treesit-ready-p 'c-sharp))
>>    (ert-test-erts-file (ert-resource-file "indent-ts.erts")))
>
> Thanks, but shouldn't we invoke treesit-ready-p with second argument
> non-nil?

Looks like it’s gone either way so far.

$ git grep 'treesit-ready-p' test/lisp/
test/lisp/align-tests.el:(autoload 'treesit-ready-p "treesit")
test/lisp/align-tests.el:  (skip-unless (treesit-ready-p 'lua))
test/lisp/progmodes/c-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'c))
test/lisp/progmodes/c-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'c))
test/lisp/progmodes/c-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'c))
test/lisp/progmodes/c-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'c))
test/lisp/progmodes/csharp-mode-tests.el:  (skip-unless (treesit-ready-p 'c-sharp))
test/lisp/progmodes/elixir-ts-mode-tests.el:  (skip-unless (and (treesit-ready-p 'elixir) (treesit-ready-p 'heex)))
test/lisp/progmodes/go-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'go))
test/lisp/progmodes/heex-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'heex))
test/lisp/progmodes/java-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'java))
test/lisp/progmodes/java-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'java))
test/lisp/progmodes/js-tests.el:  (skip-unless (treesit-ready-p 'javascript))
test/lisp/progmodes/lua-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'lua))
test/lisp/progmodes/lua-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'lua))
test/lisp/progmodes/lua-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'lua))
test/lisp/progmodes/lua-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'lua))
test/lisp/progmodes/python-tests.el:     (skip-unless (treesit-ready-p 'python))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/ruby-ts-mode-tests.el:     (skip-unless (treesit-ready-p 'ruby t))
test/lisp/progmodes/rust-ts-mode-tests.el:  (skip-unless (treesit-ready-p 'rust))
test/lisp/progmodes/typescript-ts-mode-tests.el:  (skip-unless (and (treesit-ready-p 'typescript)
test/lisp/progmodes/typescript-ts-mode-tests.el:                    (treesit-ready-p 'tsx)))





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70345; Package emacs. (Sat, 27 Apr 2024 19:19:01 GMT) Full text and rfc822 format available.

Message #49 received at 70345 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: john muhl <jm <at> pub.pink>
Cc: dmitry <at> gutov.dev, 70345 <at> debbugs.gnu.org, theo <at> thornhill.no,
 jacobtophatleeming <at> gmail.com
Subject: Re: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if
 statements with single-statement body
Date: Sat, 27 Apr 2024 22:18:09 +0300
> From: john muhl <jm <at> pub.pink>
> Cc: jacobtophatleeming <at> gmail.com, dmitry <at> gutov.dev, 70345 <at> debbugs.gnu.org,
>  theo <at> thornhill.no
> Date: Sat, 27 Apr 2024 12:13:12 -0500
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > Thanks, but shouldn't we invoke treesit-ready-p with second argument
> > non-nil?
> 
> Looks like it’s gone either way so far.

"Two wrongs don't make a right."  Without the 2nd arg, the function
complains:

  Warning (treesit): Cannot activate tree-sitter, because language grammar for c-sharp is unavailable (not-found): (libtree-sitter-c-sharp libtree-sitter-c-sharp.dll) No such file or directory
    skipped  2/2  csharp-ts-mode-test-indentation (0.007771 sec)

So I've added the 2nd argument to your patch and installed it on the
emacs-29 branch.

Thanks.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 26 May 2024 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 6 days ago.

Previous Next


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