Subject: Re: bug#59897: 29.0.60; csharp-ts-mode: variable-name fontified as method when invoking method with generic type-argument.

From: Theodor Thornhill <[email-masked]>
Date: Thu, 08 Dec 2022 11:12:54 +0100

Jostein Kjønigsen <[email-masked]> writes:

> When I use the new csharp-ts-mode, method fontification is usually accurate with only 1 exception which I have
> encountered so far:
>
> When calling methods on objects, and that method accepts a generic type-argument. You typically see this in
> Startup.cs-like files in ASP.Net Core projects:
>
> services.AddSomeExtensionWithoutTypeArguments();
> services.AddSomeExtensionWithTypeArguments<MyType>();
>
> In the above cases we see that fontification of "services" differs.
>
> For the first line, services is fontified using font-lock-variable-name-face (correct), but in the latter case services
> is fontified using font-lock-function-name-face (incorrect).
>
> In both cases I expected services to be fontified using font-lock-variable-name-face.
>

Can you test this patch, Jostein, and if you're happy, please install,
Yuan :-)

BTW, I think the ruleset is getting pretty gnarly in csharp-mode, so
maybe we should consider slimming it down a little (without losing
granularity) for perf reasons down the line!

Theo

>From 34fa2bc67ddffca65f219644f055f75a2b073aba Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <[email-masked]>
Date: Thu, 8 Dec 2022 11:08:28 +0100
Subject: [PATCH] Add expression for generic_name in csharp-ts-mode

Given the below example, we want 'services' to be font-locked in
'font-lock-variable-name-face' in all cases.  Previously this only
worked in the first case, and the other was font-locked as
'font-lock-function-name-face'.

namespace Foo {
    void Foo() {
        services.Add();
        services.Add<MyType>();
    }
}

* lisp/progmodes/csharp-mode.el (csharp-ts-mode--font-lock-settings):
Add new query that makes the mentioned example work.

(bug#59897)
---
 lisp/progmodes/csharp-mode.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 82e3bc0d54..bedf3f4342 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -784,6 +784,10 @@ csharp-ts-mode--font-lock-settings
      (invocation_expression
       (member_access_expression
        (generic_name (identifier) @font-lock-function-name-face)))
+     (invocation_expression
+      (member_access_expression
+       expression: (identifier) @font-lock-variable-name-face
+       name: (generic_name (type_argument_list (identifier)))))
      (invocation_expression
       (member_access_expression
        ((identifier) @font-lock-variable-name-face
-- 
2.34.1