Subject: Re: bug#60376: 29.0.60; Standardize csharp-ts-mode's font-lock features

From: Theodor Thornhill <[email-masked]>
Date: Fri, 30 Dec 2022 20:30:43 +0100

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

>> On 30 Dec 2022, at 16:46, Eli Zaretskii <[email-masked]> wrote:
>> 
>> 
>>> 
>>> Date: Fri, 30 Dec 2022 15:39:20 +0100
>>> Cc: [email-masked], [email-masked], [email-masked]
>>> From: Jostein Kjønigsen <[email-masked]>
>>> 
>>> To be clear: I think csharp-ts-mode works well beyond 85% (it's what I 
>>> use as my daily driver), but the syntax-highlighting at level 3 may be 
>>> more excessive than some people (like Stefan) prefer.
>>> 
>>> If we instead for these "major" changes suggested by Yuan, instead aim 
>>> for just moving some "smaller" implementation-detail 
>>> (function-invocations and property-highlighting) to level 4, I think we 
>>> she be able to get something which is mostly what Stefan would expect 
>>> and prefer, and it would be a much smaller change.
>>> 
>>> Then we can take a look at those bigger changes (standardized features, 
>>> enabling/disabling them individually, as end-users, etc) for Emacs-30.
>>> 
>>> I think that's a more realistic plan. Does that sound OK?
>> 
>> Yes, it does.  And I urge you to submit patches to that effect.
>> 
>> Thanks.
>
> Theo has offered to come up with some patches and I’ll do my best to battle-test them. 
>
> Hopefully we can get this done quickly enough to suit your taste ;)
>

Let's start here!

If you're satisfied, Jostein, report back, then you install, Yuan?

Then rinse repeat :-)

Theo

>From 36ba718d0f4c528b7518da33d9c4e591f578ab10 Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <[email-masked]>
Date: Fri, 30 Dec 2022 20:26:09 +0100
Subject: [PATCH] Tweak csharp-mode font-lock-settings

* lisp/progmodes/csharp-mode.el (csharp-ts-mode--font-lock-settings):
Rearrange features.
(csharp-ts-mode): Rearrange features.
---
 lisp/progmodes/csharp-mode.el | 53 +++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 21 deletions(-)

diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 66e4a65184..bd0e023db1 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -692,25 +692,47 @@ csharp-ts-mode--keywords
 
 (defvar csharp-ts-mode--font-lock-settings
   (treesit-font-lock-rules
+   :language 'c-sharp
+   :feature 'expression
+   '((conditional_expression (identifier) @font-lock-variable-name-face)
+     (postfix_unary_expression (identifier)* @font-lock-variable-name-face)
+     (assignment_expression (identifier) @font-lock-variable-name-face))
+
+   :language 'c-sharp
+   :feature 'bracket
+   '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
+
+   :language 'c-sharp
+   :feature 'delimiter
+   '((["," ":" ";"]) @font-lock-delimiter-face)
+
+   :language 'c-sharp
+   :feature 'error
+   '((ERROR) @font-lock-warning-face)
+
    :language 'c-sharp
    :override t
    :feature 'comment
-   '((comment)  @font-lock-comment-face)
+   '((comment) @font-lock-comment-face)
+
    :language 'c-sharp
    :override t
    :feature 'keyword
    `([,@csharp-ts-mode--keywords] @font-lock-keyword-face
      (modifier) @font-lock-keyword-face
      (this_expression) @font-lock-keyword-face)
+
    :language 'c-sharp
    :override t
-   :feature 'attribute
+   :feature 'property
    `((attribute (identifier) @font-lock-property-face (attribute_argument_list))
      (attribute (identifier) @font-lock-property-face))
+
    :language 'c-sharp
    :override t
    :feature 'escape-sequence
    '((escape_sequence) @font-lock-escape-face)
+
    :language 'c-sharp
    :override t
    :feature 'literal
@@ -718,6 +740,7 @@ csharp-ts-mode--font-lock-settings
      (real_literal) @font-lock-number-face
      (null_literal) @font-lock-constant-face
      (boolean_literal) @font-lock-constant-face)
+
    :language 'c-sharp
    :override t
    :feature 'string
@@ -730,6 +753,7 @@ csharp-ts-mode--font-lock-settings
       "$\""
       "@$\""
       "$@\""] @font-lock-string-face)
+
    :language 'c-sharp
    :override t
    :feature 'type
@@ -750,14 +774,14 @@ csharp-ts-mode--font-lock-settings
       target: (identifier) @font-lock-type-face)
      (type_of_expression (identifier) @font-lock-type-face)
      (object_creation_expression (identifier) @font-lock-type-face))
+
    :language 'c-sharp
    :feature 'definition
    :override t
    '((qualified_name (identifier) @font-lock-type-face)
      (using_directive (identifier) @font-lock-type-face)
      (using_directive (name_equals
-                       (identifier) @font-lock-type-face
-                       ["="] @default-face))
+                       (identifier) @font-lock-type-face))
 
      (enum_declaration (identifier) @font-lock-type-face)
      (enum_member_declaration (identifier) @font-lock-variable-name-face)
@@ -820,24 +844,11 @@ csharp-ts-mode--font-lock-settings
 
      (binary_expression (identifier) @font-lock-variable-name-face)
      (argument (identifier) @font-lock-variable-name-face))
-   :language 'c-sharp
-   :feature 'expression
-   '((conditional_expression (identifier) @font-lock-variable-name-face)
-     (postfix_unary_expression (identifier)* @font-lock-variable-name-face)
-     (assignment_expression (identifier) @font-lock-variable-name-face))
-   :language 'c-sharp
-   :feature 'bracket
-   '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
-
-   :language 'c-sharp
-   :feature 'delimiter
-   '((["," ":" ";"]) @font-lock-delimiter-face)
 
    :language 'c-sharp
    :feature 'escape-sequence
    :override t
-   '((escape_sequence) @font-lock-escape-face
-     (ERROR) @font-lock-warning-face)))
+   '((escape_sequence) @font-lock-escape-face)))
 
 ;;;###autoload
 (add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-mode))
@@ -903,9 +914,9 @@ csharp-ts-mode
   (setq-local treesit-font-lock-settings csharp-ts-mode--font-lock-settings)
   (setq-local treesit-font-lock-feature-list
               '(( comment definition)
-                ( keyword string escape-sequence type)
-                ( attribute constant expression literal)
-                ( bracket delimiter)))
+                ( keyword string type)
+                ( constant escape-sequence expression literal property)
+                ( bracket delimiter error)))
 
   ;; Imenu.
   (setq-local treesit-simple-imenu-settings
-- 
2.34.1