on master help sign in
highlights: add type.parameter scope to several more languages (#8718)

* typescript * go * haskell * ocaml * kotlin (+ bugfix)

commitf73e9a8d15fd5a87d472a49808baf42ba403f9bf authorJoey Hain <hain.joseph@gmail.com> dateSun 5 Nov 2023, 17:54 (3 years ago) parenta98ad13
8 files changed+63−8
runtime/queries/_typescript/highlights.scm+2 runtime/queries/_typescript/locals.scm+17 runtime/queries/go/highlights.scm+12−4 runtime/queries/go/locals.scm+10−2 runtime/queries/haskell/highlights.scm+1−1 runtime/queries/kotlin/highlights.scm+4−1 runtime/queries/kotlin/locals.scm+15 runtime/queries/ocaml/highlights.scm+2
runtime/queries/_typescript/highlights.scm+2
@@ -107,6 +107,8 @@
107107; Types
108108; -----
109109
110+(type_parameter
111+ name: (type_identifier) @type.parameter)
110112(type_identifier) @type
111113(predefined_type) @type.builtin
112114
runtime/queries/_typescript/locals.scm+17
@@ -1,6 +1,18 @@
1+; Scopes
2+;-------
3+
4+[
5+ (type_alias_declaration)
6+ (class_declaration)
7+ (interface_declaration)
8+] @local.scope
9+
110; Definitions
211;------------
312
13+(type_parameter
14+ name: (type_identifier) @local.definition)
15+
416; Javascript and Typescript Treesitter grammars deviate when defining the
517; tree structure for parameters, so we need to address them in each specific
618; language instead of ecma.
@@ -14,3 +26,8 @@
1426; (i?: t = 1) // Invalid but still posible to hihglight.
1527(optional_parameter
1628 (identifier) @local.definition)
29+
30+; References
31+;-----------
32+
33+(type_identifier) @local.reference
runtime/queries/go/highlights.scm+12−4
@@ -11,6 +11,18 @@
1111 function: (selector_expression
1212 field: (field_identifier) @function.method))
1313
14+
15+; Types
16+
17+(type_parameter_list
18+ (parameter_declaration
19+ name: (identifier) @type.parameter))
20+
21+((type_identifier) @type.builtin
22+ (match? @type.builtin "^(any|bool|byte|comparable|complex128|complex64|error|float32|float64|int|int16|int32|int64|int8|rune|string|uint|uint16|uint32|uint64|uint8|uintptr)$"))
23+
24+(type_identifier) @type
25+
1426; Function definitions
1527
1628(function_declaration
@@ -30,10 +42,6 @@
3042(parameter_declaration (identifier) @variable.parameter)
3143(variadic_parameter_declaration (identifier) @variable.parameter)
3244
33−((type_identifier) @type.builtin
34− (match? @type.builtin "^(any|bool|byte|comparable|complex128|complex64|error|float32|float64|int|int16|int32|int64|int8|rune|string|uint|uint16|uint32|uint64|uint8|uintptr)$"))
35−
36−(type_identifier) @type
3745(type_spec
3846 name: (type_identifier) @constructor)
3947(field_identifier) @variable.other.member
runtime/queries/go/locals.scm+10−2
@@ -1,9 +1,17 @@
11; Scopes
22
3−(block) @local.scope
3+[
4+ (function_declaration)
5+ (type_declaration)
6+ (block)
7+] @local.scope
48
59; Definitions
610
11+(type_parameter_list
12+ (parameter_declaration
13+ name: (identifier) @local.definition))
14+
715(parameter_declaration (identifier) @local.definition)
816(variadic_parameter_declaration (identifier) @local.definition)
917
@@ -27,4 +35,4 @@
2735
2836(identifier) @local.reference
2937(field_identifier) @local.reference
30−
38+(type_identifier) @local.reference
runtime/queries/haskell/highlights.scm+1−1
@@ -124,7 +124,7 @@
124124;; Types
125125
126126(type) @type
127−(type_variable) @type
127+(type_variable) @type.parameter
128128
129129(constructor) @constructor
130130
runtime/queries/kotlin/highlights.scm+4−1
@@ -244,7 +244,10 @@
244244 . (identifier)) @namespace
245245
246246((type_identifier) @type.builtin
247− (#match? @function.builtin "^(Byte|Short|Int|Long|UByte|UShort|UInt|ULong|Float|Double|Boolean|Char|String|Array|ByteArray|ShortArray|IntArray|LongArray|UByteArray|UShortArray|UIntArray|ULongArray|FloatArray|DoubleArray|BooleanArray|CharArray|Map|Set|List|EmptyMap|EmptySet|EmptyList|MutableMap|MutableSet|MutableList)$"))
247+ (#match? @type.builtin "^(Byte|Short|Int|Long|UByte|UShort|UInt|ULong|Float|Double|Boolean|Char|String|Array|ByteArray|ShortArray|IntArray|LongArray|UByteArray|UShortArray|UIntArray|ULongArray|FloatArray|DoubleArray|BooleanArray|CharArray|Map|Set|List|EmptyMap|EmptySet|EmptyList|MutableMap|MutableSet|MutableList)$"))
248+
249+(type_parameter
250+ (type_identifier) @type.parameter)
248251
249252(type_identifier) @type
250253
runtime/queries/kotlin/locals.scmnew file+15
@@ -0,0 +1,15 @@
1+; Scopes
2+
3+[
4+ (class_declaration)
5+ (function_declaration)
6+] @local.scope
7+
8+; Definitions
9+
10+(type_parameter
11+ (type_identifier) @local.definition)
12+
13+; References
14+
15+(type_identifier) @local.reference
runtime/queries/ocaml/highlights.scm+2
@@ -8,6 +8,8 @@
88
99[(class_name) (class_type_name) (type_constructor)] @type
1010
11+(type_variable) @type.parameter
12+
1113[(constructor_name) (tag)] @constructor
1214
1315; Functions