diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index ede17c9..bc55504 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -7,6 +7,9 @@ ((value_identifier) @constant.macro (#match? @constant.macro "^\\.*$")) + +((value_identifier) @variable) + [ (type_identifier) (unit_type) @@ -14,23 +17,44 @@ (list_pattern) ] @type +((type_identifier) @type.builtin + (#any-of? @type.builtin + "int" "char" "string" "float" "bool" "unit")) + [ (variant_identifier) (polyvar_identifier) -] @constant +] @constructor (record_type_field (property_identifier) @property) (record_field (property_identifier) @property) (object (field (property_identifier) @property)) (object_type (field (property_identifier) @property)) -(member_expression (property_identifier) @property) -(module_identifier) @namespace +(module_identifier) @module + +(member_expression (property_identifier) @variable.member) + +(value_identifier_path + (module_identifier) + (value_identifier) @variable) + + +(record_pattern + (value_identifier_path + (value_identifier) @variable.member)) + +(record_pattern + (value_identifier) @variable) + +(labeled_argument + label: (value_identifier) @variable.parameter) + ; Parameters ;---------------- -(list_pattern (value_identifier) @parameter) -(spread_pattern (value_identifier) @parameter) +(list_pattern (value_identifier) @variable.parameter) +(spread_pattern (value_identifier) @variable.parameter) ; String literals ;---------------- @@ -40,11 +64,8 @@ (template_string) ] @string -(template_substitution - "${" @punctuation.bracket - "}" @punctuation.bracket) @embedded -(character) @string.special +(character) @character (escape_sequence) @string.escape ; Other literals @@ -53,34 +74,57 @@ [ (true) (false) -] @constant.builtin +] @boolean (number) @number -(polyvar) @constant -(polyvar_string) @constant +(polyvar) @constructor +(polyvar_string) @constructor ; Functions ;---------- ; parameter(s) in parens -[ - (parameter (value_identifier)) - (labeled_parameter (value_identifier)) -] @parameter + +(parameter (value_identifier) @variable.parameter) +(labeled_parameter (value_identifier) @variable.parameter) ; single parameter with no parens -(function parameter: (value_identifier) @parameter) +(function parameter: (value_identifier) @variable.parameter) ; first-level descructuring (required for nvim-tree-sitter as it only matches direct ; children and the above patterns do not match destructuring patterns in NeoVim) -(parameter (tuple_pattern (tuple_item_pattern (value_identifier) @parameter))) -(parameter (array_pattern (value_identifier) @parameter)) -(parameter (record_pattern (value_identifier) @parameter)) +(parameter (tuple_pattern (tuple_item_pattern (value_identifier) @variable.parameter))) +(parameter (array_pattern (value_identifier) @variable.parameter)) +(parameter (record_pattern (value_identifier) @variable.parameter)) + +; function identifier in let binding +(let_binding + pattern: (value_identifier) @function + body: (function)) + +; function calls + +(call_expression + function: (value_identifier_path + _ + (value_identifier) @function.call)) + +(call_expression + function: (value_identifier) @function.call) + +; highlight the right-hand side of a pipe operator as a function call +(pipe_expression + _ + [(value_identifier_path + _ + (value_identifier) @function.call) + (value_identifier) @function.call]) + ; Meta ;----- -(decorator_identifier) @annotation +(decorator_identifier) @attribute (extension_identifier) @keyword ("%") @keyword @@ -88,33 +132,44 @@ ; Misc ;----- -(subscript_expression index: (string) @property) -(polyvar_type_pattern "#" @constant) +(polyvar_type_pattern "#" @constructor) [ - ("include") - ("open") -] @include + "include" + "open" +] @keyword.import + + +[ + "private" + "mutable" + "rec" +] @keyword.modifier + +[ + "type" +] @keyword.type [ + "and" + "with" "as" +] @keyword.operator + +[ "export" "external" "let" "module" - "mutable" - "private" - "rec" - "type" - "and" "assert" "await" - "with" "lazy" "constraint" ] @keyword -((function "async" @keyword)) +(("await") @keyword.coroutine) + +((function "async" @keyword.coroutine)) (module_unpack "unpack" @keyword) @@ -123,17 +178,17 @@ "else" "switch" "when" -] @conditional +] @keyword.conditional [ "exception" "try" "catch" -] @exception +] @keyword.exception (call_expression - function: (value_identifier) @exception - (#eq? @exception "raise")) + function: (value_identifier) @keyword.exception + (#eq? @keyword.exception "raise")) [ "for" @@ -141,12 +196,13 @@ "to" "downto" "while" -] @repeat +] @keyword.repeat [ "." "," "|" + ":" ] @punctuation.delimiter [ @@ -174,6 +230,7 @@ "|>" ":>" "+=" + "=>" (uncurry) ] @operator @@ -188,8 +245,16 @@ "}" "[" "]" + "<" + ">" ] @punctuation.bracket +(unit ["(" ")"] @constant.builtin) + +(template_substitution + "${" @punctuation.special + "}" @punctuation.special) @none + (polyvar_type [ "[" @@ -201,12 +266,11 @@ [ "~" "?" - "=>" ".." "..." ] @punctuation.special -(ternary_expression ["?" ":"] @operator) +(ternary_expression ["?" ":"] @keyword.conditional.ternary) ; JSX ;---------- diff --git a/test/highlight/decorators.res b/test/highlight/decorators.res index 66adc13..f0a7d7e 100644 --- a/test/highlight/decorators.res +++ b/test/highlight/decorators.res @@ -1,5 +1,5 @@ @name -//<- annotation +//<- attribute @@name -//<- annotation +//<- attribute diff --git a/test/highlight/expressions.res b/test/highlight/expressions.res index ed756d6..f9fce81 100644 --- a/test/highlight/expressions.res +++ b/test/highlight/expressions.res @@ -9,25 +9,25 @@ foo->bar == +x +. 1.0 // ^ property switch foo { -// <- conditional +// <- keyword.conditional | list{1, x, ...rest} => //^ type // ^ number -// ^ parameter +// ^ variable.parameter // ^ punctuation.special -// ^ parameter -// ^ punctuation.special +// ^ variable.parameter +// ^ operator 42 | list{1, 2, ...list{b, ..._} as rest} => rest -// ^ parameter +// ^ variable.parameter // ^ variable | exception Js.Exn.Error(_) => 99 -//^ exception +//^ keyword.exception } switch bar { | #...Mod.t => 33 -//^ constant +//^ constructor } { foo, bar: baz, qux: 1 } @@ -35,16 +35,16 @@ switch bar { // ^ property exception InputClosed(string) -//<- exception +//<- keyword.exception raise(InputClosed("The stream has closed!")) -//<- exception +//<- keyword.exception try { -//<- exception +//<- keyword.exception someOtherJSFunctionThatThrows() } catch { -// ^ exception +// ^ keyword.exception | Not_found => 1 // catch a ReScript exception | Invalid_argument(_) => 2 // catch a second ReScript exception | Js.Exn.Error(obj) => 3 // catch the JS exception @@ -55,3 +55,26 @@ let c = list{a, ...list{b}} // ^ type // ^ variable // ^ variable + +let x = fn() +// ^ function.call + +let y = x->M.f->f +// ^function.call +// ^function.call + +let v = M.v +// ^variable + +let {x} = y +// ^variable + +let {X.x} = y +// ^variable.member + +let x = y.x +// ^variable.member + +f(~a=b, ()) +// ^variable.parameter +// ^constant.builtin diff --git a/test/highlight/functions.res b/test/highlight/functions.res index 59d4bc8..153c38b 100644 --- a/test/highlight/functions.res +++ b/test/highlight/functions.res @@ -1,16 +1,13 @@ let inc = n => n + 1 -// ^ parameter +// ^ variable.parameter // ^ punctuation.special +// ^ function let fn = (a, (b, c), {d, e}, [f, g]) => a + b + c + d + e + f + g -// ^ parameter -// ^ parameter -// ^ parameter -// ^ parameter - -let uncurry = (. u, .x) => (u, x) -// ^ operator -// ^ operator +// ^ variable.parameter +// ^ variable.parameter +// ^ variable.parameter +// ^ variable.parameter let get = async (id) => id -// ^ keyword +// ^ keyword.coroutine diff --git a/test/highlight/literals.res b/test/highlight/literals.res index fcbbe88..0cad50c 100644 --- a/test/highlight/literals.res +++ b/test/highlight/literals.res @@ -1,26 +1,31 @@ /**/ #polyvar -// ^ constant -// ^ constant +// ^ constructor +// ^ constructor /**/ #"polyvar" -// ^ constant -// ^ constant -// ^ constant +// ^ constructor +// ^ constructor +// ^ constructor /**/ #\"polyvar" -// ^ constant -// ^ constant -// ^ constant -// ^ constant +// ^ constructor +// ^ constructor +// ^ constructor +// ^ constructor /**/ #77 -// ^ constant -// ^ constant +// ^ constructor +// ^ constructor /**/ 'R' -// ^ string.special -// ^ string.special +// ^ character +// ^ character /**/ '\\' // ^ string.escape + +/**/ `${hello}` +// ^ punctuation.special +// ^ punctuation.special +// ^ punctuation.special diff --git a/test/highlight/modules.res b/test/highlight/modules.res index bd7ba1e..b512cb7 100644 --- a/test/highlight/modules.res +++ b/test/highlight/modules.res @@ -1,23 +1,23 @@ @@warning("-27") -//<- annotation -//^annotation +//<- attribute +//^attribute // ^ string include NumericCurve({ -// ^ include -// ^ namespace +// ^ keyword.import +// ^ module let foo = foo }) let {baz, _} = module(User.Inner) // ^ keyword -// ^ namespace -// ^ namespace +// ^ module +// ^ module module Belt = { include (Belt: module type of Belt with module Map := Belt.Map and module Result := Belt.Result) - // ^ include + // ^ keyword.import // ^ keyword // ^ keyword // ^ operator @@ -29,7 +29,7 @@ let a = module( type t let hello = "Hello" }: X -// ^ namespace +// ^ module ) module B = unpack(a) @@ -46,5 +46,5 @@ module A: A = { } let packedA = module(A: A) -// ^ namespace -// ^ namespace +// ^ module +// ^ module diff --git a/test/highlight/type_declarations.res b/test/highlight/type_declarations.res index e054f20..0b22969 100644 --- a/test/highlight/type_declarations.res +++ b/test/highlight/type_declarations.res @@ -1,13 +1,13 @@ type rec t = -//<- keyword -// ^ keyword +//<- keyword.type +// ^ keyword.modifier // ^ type | Node(t, t) -// ^ constant +// ^ constructor // ^ type | Terminal -// ^ constant +// ^ constructor | Component(module(Foo.t)) // ^ keyword