GNU bug report logs - #78130
[PATCH] 31.0.50; csharp-ts-mode does not highlight generic types correctly everywhere

Previous Next

Package: emacs;

Reported by: Jostein Kjønigsen <jostein <at> secure.kjonigsen.net>

Date: Tue, 29 Apr 2025 09:53:02 UTC

Severity: normal

Tags: patch

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

To reply to this bug, email your comments to 78130 AT debbugs.gnu.org.
There is no need to reopen the bug first.

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#78130; Package emacs. (Tue, 29 Apr 2025 09:53:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jostein Kjønigsen <jostein <at> secure.kjonigsen.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 29 Apr 2025 09:53:02 GMT) Full text and rfc822 format available.

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

From: Jostein Kjønigsen <jostein <at> secure.kjonigsen.net>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] 31.0.50; csharp-ts-mode does not highlight generic types
 correctly everywhere
Date: Tue, 29 Apr 2025 11:51:47 +0200
[Message part 1 (text/plain, inline)]
Hey everyone.

When using charp-ts-mode to edit C# files, you often work with generic-types (ie List<string>, etc). csharp-ts-mode has treesitter selectors for this type of syntax, but the current implementation constraints it to only be used in specialized circumstances, when we really want to apply it all over the place.

As an example, generic return-types in function declarations are currently not highlighted correctly.

Attached is a patch which removes this unneeded narrowing of the selector and makes generic types look correct everywhere.

It also corrects a small semantic error (property-use vs variable-use) in initializer-expressions, but I didn't feel like making a separate bug-report for that :)

—
Kind Regards
Jostein Kjønigsen



[Message part 2 (text/html, inline)]
[0001-csharp-mode.el-Fix-fontification-of-generic-types.patch (application/octet-stream, attachment)]
[Message part 4 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78130; Package emacs. (Tue, 29 Apr 2025 11:14:01 GMT) Full text and rfc822 format available.

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

From: Jostein Kjønigsen <jostein <at> secure.kjonigsen.net>
To: 78130 <at> debbugs.gnu.org
Subject: Re: bug#78130: Acknowledgement ([PATCH] 31.0.50; csharp-ts-mode does
 not highlight generic types correctly everywhere)
Date: Tue, 29 Apr 2025 13:13:27 +0200
[Message part 1 (text/plain, inline)]
Just a FYI: I've uncovered some use-cases which my patch does not address correctly: namely function invocations.

The bug is still real, but I'll be restructuring my fix and submitting when I think I have something which works better.

—
Kind Regards
Jostein Kjønigsen

> On 29 Apr 2025, at 11:53, GNU bug Tracking System <help-debbugs <at> gnu.org> wrote:
> 
> Thank you for filing a new bug report with debbugs.gnu.org.
> 
> This is an automatically generated reply to let you know your message
> has been received.
> 
> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.
> 
> Your message has been sent to the package maintainer(s):
> bug-gnu-emacs <at> gnu.org
> 
> If you wish to submit further information on this problem, please
> send it to 78130 <at> debbugs.gnu.org.
> 
> Please do not send mail to help-debbugs <at> gnu.org unless you wish
> to report a problem with the Bug-tracking system.
> 
> -- 
> 78130: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78130
> GNU Bug Tracking System
> Contact help-debbugs <at> gnu.org with problems

[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78130; Package emacs. (Tue, 29 Apr 2025 19:53:06 GMT) Full text and rfc822 format available.

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

From: Jostein Kjønigsen <jostein <at> secure.kjonigsen.net>
To: 78130 <at> debbugs.gnu.org
Cc: Yuan Fu <casouri <at> gmail.com>
Subject: Re: bug#78130: Acknowledgement ([PATCH] 31.0.50; csharp-ts-mode does
 not highlight generic types correctly everywhere)
Date: Tue, 29 Apr 2025 21:51:54 +0200
[Message part 1 (text/plain, inline)]
Attached is a better patch, which addresses a lot of different areas of C# fontification.

Overall I think these are pure improvements:

- fontification of generic types with namespace-prefixes
- function-call parameters
- variable use in string interpolation
- implicitly typed parameters in lambda-expressions
- index-expressions
- variables used in return-statements
- variables used in binary expressions

What might warrant some review is the use of the (:match) selector to identify local variables (as opposed to properties or types) for a more consistent fontification. This is the first time I'm using it, and I see there's some repetition in the implementation... Could this be improved somehow?

Do we have a "emacsy" way or convention to do this which I could have applied, or is it still a bit early wrt treesitter based modes?





—
Kind Regards
Jostein Kjønigsen

> On 29 Apr 2025, at 13:13, Jostein Kjønigsen <jostein <at> secure.kjonigsen.net> wrote:
> 
> Just a FYI: I've uncovered some use-cases which my patch does not address correctly: namely function invocations.
> 
> The bug is still real, but I'll be restructuring my fix and submitting when I think I have something which works better.
> 
> —
> Kind Regards
> Jostein Kjønigsen
> 
>> On 29 Apr 2025, at 11:53, GNU bug Tracking System <help-debbugs <at> gnu.org> wrote:
>> 
>> Thank you for filing a new bug report with debbugs.gnu.org.
>> 
>> This is an automatically generated reply to let you know your message
>> has been received.
>> 
>> Your message is being forwarded to the package maintainers and other
>> interested parties for their attention; they will reply in due course.
>> 
>> Your message has been sent to the package maintainer(s):
>> bug-gnu-emacs <at> gnu.org
>> 
>> If you wish to submit further information on this problem, please
>> send it to 78130 <at> debbugs.gnu.org.
>> 
>> Please do not send mail to help-debbugs <at> gnu.org unless you wish
>> to report a problem with the Bug-tracking system.
>> 
>> -- 
>> 78130: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78130
>> GNU Bug Tracking System
>> Contact help-debbugs <at> gnu.org with problems
> 

[Message part 2 (text/html, inline)]
[0001-csharp-mode.el-Improve-csharp-ts-mode-fontification.patch (application/octet-stream, attachment)]
[Message part 4 (text/html, inline)]

Reply sent to Yuan Fu <casouri <at> gmail.com>:
You have taken responsibility. (Thu, 01 May 2025 07:55:03 GMT) Full text and rfc822 format available.

Notification sent to Jostein Kjønigsen <jostein <at> secure.kjonigsen.net>:
bug acknowledged by developer. (Thu, 01 May 2025 07:55:04 GMT) Full text and rfc822 format available.

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

From: Yuan Fu <casouri <at> gmail.com>
To: Jostein Kjønigsen <jostein <at> secure.kjonigsen.net>
Cc: 78130-done <at> debbugs.gnu.org
Subject: Re: bug#78130: Acknowledgement ([PATCH] 31.0.50; csharp-ts-mode does
 not highlight generic types correctly everywhere)
Date: Thu, 1 May 2025 00:54:19 -0700

> On Apr 29, 2025, at 12:51 PM, Jostein Kjønigsen <jostein <at> secure.kjonigsen.net> wrote:
> 
> Attached is a better patch, which addresses a lot of different areas of C# fontification.
> 
> Overall I think these are pure improvements:
> 
> - fontification of generic types with namespace-prefixes
> - function-call parameters
> - variable use in string interpolation
> - implicitly typed parameters in lambda-expressions
> - index-expressions
> - variables used in return-statements
> - variables used in binary expressions
> 
> What might warrant some review is the use of the (:match) selector to identify local variables (as opposed to properties or types) for a more consistent fontification. This is the first time I'm using it, and I see there's some repetition in the implementation... Could this be improved somehow?
> 
> Do we have a "emacsy" way or convention to do this which I could have applied, or is it still a bit early wrt treesitter based modes?
> 

Great work! The use of :match seems legit to me. Rust-ts-mode has something similar for fortifying variable vs type, it doesn’t use it as many as here though. A bit strange for the grammar to put properties on identifier too. I don’t have any good idea for reducing the duplication. 

I applied the patch to master. Thanks!

Yuan



This bug report was last modified 23 days ago.

Previous Next


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