]> git.eshelyaron.com Git - emacs.git/commitdiff
Adjust function-call fontification in csharp-ts-mode (bug#60376)
authorJostein Kjønigsen <jostein@kjonigsen.net>
Sun, 1 Jan 2023 16:27:06 +0000 (17:27 +0100)
committerYuan Fu <casouri@gmail.com>
Sun, 1 Jan 2023 23:22:06 +0000 (15:22 -0800)
- Ensure method-invocations are highlighted only on level 4.
- Ensure consistent fontification of variable declarations
  (don't highlight usage of all variables).
- Fix issues with highlighting types in new() expressions.
- Fix issues with generic types in variable-declarations not using "var".
- Use fewer, more general queries for function-invocations. simplify code.

* lisp/progmodes/csharp-mode.el (csharp-ts-mode--font-lock-settings):
Change rules.
(csharp-ts-mode): Update feature list.

lisp/progmodes/csharp-mode.el

index da64daf9848b0c4e223cfd38e13ed27400c2c926..473e8f49fd39e9f88b8f0afe0110dbf72bcd1843 100644 (file)
@@ -696,7 +696,7 @@ compilation and evaluation time conflicts."
    :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))
+     (initializer_expression (assignment_expression left: (identifier) @font-lock-variable-name-face)))
 
    :language 'c-sharp
    :feature 'bracket
@@ -764,8 +764,12 @@ compilation and evaluation time conflicts."
       (identifier) @font-lock-type-face)
      (type_argument_list
       (identifier) @font-lock-type-face)
-     (generic_name
-      (identifier) @font-lock-type-face)
+     (type_argument_list
+      (generic_name
+       (identifier) @font-lock-type-face))
+     (base_list
+      (generic_name
+       (identifier) @font-lock-type-face))
      (array_type
       (identifier) @font-lock-type-face)
      (cast_expression (identifier) @font-lock-type-face)
@@ -773,7 +777,12 @@ compilation and evaluation time conflicts."
      (type_parameter_constraints_clause
       target: (identifier) @font-lock-type-face)
      (type_of_expression (identifier) @font-lock-type-face)
-     (object_creation_expression (identifier) @font-lock-type-face))
+     (object_creation_expression
+      type: (identifier) @font-lock-type-face)
+     (object_creation_expression
+      type: (generic_name (identifier) @font-lock-type-face))
+     (as_expression right: (identifier) @font-lock-type-face)
+     (as_expression right: (generic_name (identifier) @font-lock-type-face)))
 
    :language 'c-sharp
    :feature 'definition
@@ -793,7 +802,6 @@ compilation and evaluation time conflicts."
      (record_declaration (identifier) @font-lock-type-face)
      (namespace_declaration (identifier) @font-lock-type-face)
      (base_list (identifier) @font-lock-type-face)
-     (property_declaration (generic_name))
      (property_declaration
       type: (nullable_type) @font-lock-type-face
       name: (identifier) @font-lock-variable-name-face)
@@ -807,29 +815,10 @@ compilation and evaluation time conflicts."
 
      (constructor_declaration name: (_) @font-lock-type-face)
 
-     (method_declaration type: (_) @font-lock-type-face)
+     (method_declaration type: [(identifier) (void_keyword)] @font-lock-type-face)
+     (method_declaration type: (generic_name (identifier) @font-lock-type-face))
      (method_declaration name: (_) @font-lock-function-name-face)
 
-     (invocation_expression
-      (member_access_expression
-       (generic_name (identifier) @font-lock-function-name-face)))
-     (invocation_expression
-      (member_access_expression
-       ((identifier) @font-lock-variable-name-face
-        (identifier) @font-lock-function-name-face)))
-     (invocation_expression
-      (identifier) @font-lock-function-name-face)
-     (invocation_expression
-      (member_access_expression
-       expression: (identifier) @font-lock-variable-name-face))
-     (invocation_expression
-      function: [(generic_name (identifier)) @font-lock-function-name-face
-                 (generic_name (type_argument_list
-                                ["<"] @font-lock-bracket-face
-                                (identifier) @font-lock-type-face
-                                [">"] @font-lock-bracket-face)
-                               )])
-
      (catch_declaration
       ((identifier) @font-lock-type-face))
      (catch_declaration
@@ -837,13 +826,30 @@ compilation and evaluation time conflicts."
        (identifier) @font-lock-variable-name-face))
 
      (variable_declaration (identifier) @font-lock-type-face)
+     (variable_declaration (generic_name (identifier) @font-lock-type-face))
      (variable_declarator (identifier) @font-lock-variable-name-face)
 
      (parameter type: (identifier) @font-lock-type-face)
+     (parameter type: (generic_name (identifier) @font-lock-type-face))
      (parameter name: (identifier) @font-lock-variable-name-face)
 
-     (binary_expression (identifier) @font-lock-variable-name-face)
-     (argument (identifier) @font-lock-variable-name-face))
+     (lambda_expression (identifier) @font-lock-variable-name-face)
+
+     (declaration_expression type: (identifier) @font-lock-type-face)
+     (declaration_expression name: (identifier) @font-lock-variable-name-face))
+
+   :language 'c-sharp
+   :feature 'function
+   '((invocation_expression
+      function: (member_access_expression
+                 name: (identifier) @font-lock-function-name-face))
+     (invocation_expression
+      function: (identifier) @font-lock-function-name-face)
+     (invocation_expression
+      function: (member_access_expression
+                 name: (generic_name (identifier) @font-lock-function-name-face)))
+     (invocation_expression
+      function: (generic_name (identifier) @font-lock-function-name-face)))
 
    :language 'c-sharp
    :feature 'escape-sequence
@@ -916,7 +922,7 @@ Key bindings:
               '(( comment definition)
                 ( keyword string type)
                 ( constant escape-sequence expression literal property)
-                ( bracket delimiter error)))
+                ( function bracket delimiter error)))
 
   ;; Imenu.
   (setq-local treesit-simple-imenu-settings