Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# highlighting improvements #1795

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 112 additions & 14 deletions runtime/queries/c-sharp/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
;; Methods
(method_declaration (identifier) @type (identifier) @function)
(method_declaration
name: (identifier) @function)

(method_declaration
type: [(identifier) (qualified_name)] @type)

(invocation_expression
(member_access_expression
name: (identifier) @function))

(invocation_expression
(member_access_expression
expression: (identifier) @variable))

(invocation_expression
function: (conditional_access_expression
(member_binding_expression
name: (identifier) @function)))

(invocation_expression
[(identifier) (qualified_name)] @function)

; Generic Method invocation with generic type
(invocation_expression
function: (generic_name
. (identifier) @function))

;; Namespaces

(namespace_declaration
name: [(identifier) (qualified_name)] @namespace)

;; Types
(interface_declaration name: (identifier) @type)
Expand All @@ -8,8 +38,10 @@
(struct_declaration (identifier) @type)
(record_declaration (identifier) @type)
(namespace_declaration name: (identifier) @type)

(using_directive (_) @namespace)
(constructor_declaration name: (identifier) @type)
(object_creation_expression [(identifier) (qualified_name)] @type)
(type_parameter_list (type_parameter) @type)

[
(implicit_type)
Expand All @@ -19,6 +51,31 @@
(predefined_type)
] @type.builtin

;; Generic Types
(type_of_expression
(generic_name
(identifier) @type))

(base_list
(generic_name
(identifier) @type))

(type_constraint
(generic_name
(identifier) @type))

(object_creation_expression
(generic_name
(identifier) @type))

(property_declaration
(generic_name
(identifier) @type))

(_
type: (generic_name
(identifier) @type))

;; Enum
(enum_member_declaration (identifier) @variable.other.member)

Expand Down Expand Up @@ -66,24 +123,37 @@
"++"
"+="
"<"
"<="
"<<"
"<<="
"="
"=="
"!"
"!="
"=>"
">"
">="
">>"
">>="
"|"
"||"
"|="
"?"
"??"
"^"
"^="
"~"
"*"
"*="
"/"
"/="
"%"
"%="
":"
".."
"&="
"->"
"??="
] @operator

[
Expand Down Expand Up @@ -131,6 +201,7 @@
"return"
"sizeof"
"stackalloc"
"static"
"struct"
"switch"
"throw"
Expand All @@ -157,6 +228,8 @@
"let"
] @keyword

(preprocessor_call) @keyword.directive
(preprocessor_call (_) @keyword.directive)

;; Linq
(from_clause (identifier) @variable)
Expand All @@ -172,13 +245,13 @@
(identifier) @variable)))

;; Exprs
(binary_expression (identifier) @variable (identifier) @variable)
(binary_expression (identifier)* @variable)
(conditional_expression (identifier) @variable)
(prefix_unary_expression (identifier) @variable)
(postfix_unary_expression (identifier)* @variable)
(assignment_expression (identifier) @variable)
(cast_expression (identifier) @type (identifier) @variable)
(binary_expression [(identifier) (qualified_name)] @variable [(identifier) (qualified_name)] @variable)
(binary_expression [(identifier) (qualified_name)]* @variable)
(conditional_expression [(identifier) (qualified_name)] @variable)
(prefix_unary_expression [(identifier) (qualified_name)] @variable)
(postfix_unary_expression [(identifier) (qualified_name)]* @variable)
(assignment_expression [(identifier) (qualified_name)] @variable)
(cast_expression [(identifier) (qualified_name)] @type [(identifier) (qualified_name)] @variable)

;; Class
(base_list (identifier) @type)
Expand All @@ -192,6 +265,10 @@
(property_declaration
type: (identifier) @type
name: (identifier) @variable)

;; Delegate

(delegate_declaration (identifier) @type)

;; Lambda
(lambda_expression) @variable
Expand All @@ -206,21 +283,29 @@
(parameter (identifier) @variable.parameter)
(parameter_modifier) @keyword

(parameter_list
(parameter
name: (identifier) @parameter))

(parameter_list
(parameter
type: [(identifier) (qualified_name)] @type))

;; Typeof
(type_of_expression (identifier) @type)
(type_of_expression [(identifier) (qualified_name)] @type)

;; Variable
(variable_declaration (identifier) @type)
(variable_declarator (identifier) @variable)
(variable_declaration [(identifier) (qualified_name)] @type)
(variable_declarator [(identifier) (qualified_name)] @variable)

;; Return
(return_statement (identifier) @variable)
(yield_statement (identifier) @variable)

;; Type
(generic_name (identifier) @type)
(type_parameter (identifier) @variable.parameter)
(type_argument_list (identifier) @type)
(type_parameter [(identifier) (qualified_name)] @variable.parameter)
(type_argument_list [(identifier) (qualified_name)] @type)

;; Type constraints
(type_parameter_constraints_clause (identifier) @variable.parameter)
Expand All @@ -236,3 +321,16 @@

;; Lock statement
(lock_statement (identifier) @variable)

;; Rest
(member_access_expression) @variable
(element_access_expression (identifier) @variable)
(argument (identifier) @variable)
(for_statement (identifier) @variable)
(for_each_statement (identifier) @variable)
(expression_statement (identifier) @variable)
(member_access_expression expression: (identifier) @variable)
(member_access_expression name: (identifier) @variable)
(conditional_access_expression [(identifier) (qualified_name)] @variable)
((identifier) @comment.unused
(#eq? @comment.unused "_"))