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

Add type fields #316

Merged
merged 7 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 6 additions & 17 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

[
(implicit_type)
(nullable_type)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might have been a mistake in the query. I don't think we'd want to color System.Int32? differently than System.Int32 in the below:

void M(System.Int32? b, System.Int32 c) { }

(pointer_type)
(function_pointer_type)
(predefined_type)
] @type.builtin

(_ type: (identifier) @type)

;; Enum
(enum_member_declaration (identifier) @property.definition)

Expand Down Expand Up @@ -187,19 +186,15 @@
(prefix_unary_expression (identifier) @variable)
(postfix_unary_expression (identifier)* @variable)
(assignment_expression (identifier) @variable)
(cast_expression (identifier) @type (identifier) @variable)
(cast_expression (_) (identifier) @variable)

;; Class
(base_list (identifier) @type)
(property_declaration (generic_name))
(property_declaration
type: (nullable_type) @type
name: (identifier) @variable)
(property_declaration
type: (predefined_type) @type
name: (identifier) @variable)
(property_declaration
type: (identifier) @type
name: (identifier) @variable)

;; Lambda
Expand All @@ -210,16 +205,11 @@

;; Parameter
(parameter
type: (identifier) @type
name: (identifier) @variable.parameter)
(parameter (identifier) @variable.parameter)
(parameter_modifier) @keyword

;; Typeof
(type_of_expression (identifier) @type)

;; Variable
(variable_declaration (identifier) @type)
(variable_declarator (identifier) @variable)

;; Return
Expand All @@ -229,15 +219,14 @@
;; Type
(generic_name (identifier) @type)
(type_parameter (identifier) @property.definition)
(type_argument_list (identifier) @type)
(as_expression right: (identifier) @type)
(is_expression right: (identifier) @type)

;; Type constraints
(type_parameter_constraints_clause (identifier) @property.definition)
(type_constraint (identifier) @type)

;; Exception
(catch_declaration (identifier) @type (identifier) @variable)
(catch_declaration (identifier) @type)
(catch_declaration (_) (identifier) @variable)

;; Switch
(switch_statement (identifier) @variable)
Expand Down
2 changes: 1 addition & 1 deletion test/highlight/baseline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public partial class Class<in TParam> where TParam : class?, notnull, F?
// ^ operator
// ^ keyword
// ^ punctuation.delimiter
// ^ type.builtin
// ^ type
// ^ operator
{
// <- punctuation.bracket
Expand Down
45 changes: 45 additions & 0 deletions test/highlight/types.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class A
{
public void M()
{
int a;
// <- type.builtin
var a;
// <- type.builtin

int? a;
// <- type.builtin
// ^ operator
A? a;
// <- type
// <- operator

int* a;
// <- type.builtin
// ^ operator
A* a;
// <- type
// <- operator

ref A* a;
// <- keyword
// ^ type
// ^ operator

var a = x is int;
// ^ type.builtin
var a = x is A;
// ^
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not highlighted due to #317.


var a = x as int;
// ^ type.builtin
var a = x as A;
// ^ type

var a = (int)x;
// ^ type.builtin
var a = (A)x;
// ^ type
}

}