From 419bd377c04f3642a6c815f4ebedceb7fc9a30af Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 20:51:14 -0600 Subject: [PATCH 01/38] Highlight variants as constructors --- queries/rescript/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index ede17c9..baa4ce2 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -17,7 +17,7 @@ [ (variant_identifier) (polyvar_identifier) -] @constant +] @constructor (record_type_field (property_identifier) @property) (record_field (property_identifier) @property) From 1ad1493cccc67d3b31e7c808cadff8ca3ef4b335 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 20:51:59 -0600 Subject: [PATCH 02/38] Add set of built-in types --- queries/rescript/highlights.scm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index baa4ce2..ddf1ba0 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -14,6 +14,10 @@ (list_pattern) ] @type +((type_identifier) @type.builtin + (#any-of? @type.builtin + "int" "char" "string" "float" "bool" "unit")) + [ (variant_identifier) (polyvar_identifier) From 32944ca5726e4215ee54f081f85bcfe4bdd9c13c Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 20:54:47 -0600 Subject: [PATCH 03/38] Update @namespace to @module It's what's in the neovim docs right now --- queries/rescript/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index ddf1ba0..b85587b 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -28,7 +28,7 @@ (object (field (property_identifier) @property)) (object_type (field (property_identifier) @property)) (member_expression (property_identifier) @property) -(module_identifier) @namespace +(module_identifier) @module ; Parameters ;---------------- From 3e82ffc875619457b10943c75f72b62d2060c46f Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 20:55:45 -0600 Subject: [PATCH 04/38] Update @parameter to @variable.parameter --- queries/rescript/highlights.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index b85587b..d5f81a1 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -33,8 +33,8 @@ ; 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 ;---------------- From 4fb7aebd342881ef21a52ad1efa27dfafcafa1a6 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 20:59:53 -0600 Subject: [PATCH 05/38] Update string interpolation and char --- queries/rescript/highlights.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index d5f81a1..1362e95 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -45,10 +45,10 @@ ] @string (template_substitution - "${" @punctuation.bracket - "}" @punctuation.bracket) @embedded + "${" @punctuation.special + "}" @punctuation.special) @embedded -(character) @string.special +(character) @character (escape_sequence) @string.escape ; Other literals From a72871e7ca709768d5b97a9500d0493ec4c78e15 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 21:11:41 -0600 Subject: [PATCH 06/38] Update parameter to @variable.parameter --- queries/rescript/highlights.scm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 1362e95..952853e 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -70,16 +70,16 @@ [ (parameter (value_identifier)) (labeled_parameter (value_identifier)) -] @parameter +] @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)) ; Meta ;----- From ef8fa564b7d15d3506a8fa9071eaa78c3eb6172f Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 21:25:50 -0600 Subject: [PATCH 07/38] Update annotation to attribute --- queries/rescript/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 952853e..7e7b016 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -84,7 +84,7 @@ ; Meta ;----- -(decorator_identifier) @annotation +(decorator_identifier) @attribute (extension_identifier) @keyword ("%") @keyword From b5a655de5b84eb441e48b595393a1257babb8685 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 21:26:13 -0600 Subject: [PATCH 08/38] Complete change of polyvar as constructors --- queries/rescript/highlights.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 7e7b016..2eb8bff 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -60,8 +60,8 @@ ] @constant.builtin (number) @number -(polyvar) @constant -(polyvar_string) @constant +(polyvar) @constructor +(polyvar_string) @constructor ; Functions ;---------- @@ -93,7 +93,7 @@ ;----- (subscript_expression index: (string) @property) -(polyvar_type_pattern "#" @constant) +(polyvar_type_pattern "#" @constructor) [ ("include") From 53eba40b553f409b2c500a22e89235021bc3dbd8 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 21:34:11 -0600 Subject: [PATCH 09/38] Specialize some of the keywords --- queries/rescript/highlights.scm | 40 ++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 2eb8bff..fd4bb9b 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -96,24 +96,34 @@ (polyvar_type_pattern "#" @constructor) [ - ("include") - ("open") -] @include + "include" + "open" +] @keyword.import + + +[ + "as" + "private" + "mutable" + "rec" +] @keyword.modifier + +[ + "type" +] @keyword.type + +[ + "and" + "with" +] @keyword.operator [ - "as" "export" "external" "let" "module" - "mutable" - "private" - "rec" - "type" - "and" "assert" "await" - "with" "lazy" "constraint" ] @keyword @@ -127,17 +137,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" @@ -145,7 +155,7 @@ "to" "downto" "while" -] @repeat +] @keyword.repeat [ "." From 37dcedd97fb588f85c11aed0d11ab2dccbc722dc Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 21:35:06 -0600 Subject: [PATCH 10/38] Move the => arrow to operators This is how it's in the ecma parser (JS) --- queries/rescript/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index fd4bb9b..0aed017 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -188,6 +188,7 @@ "|>" ":>" "+=" + "=>" (uncurry) ] @operator @@ -215,7 +216,6 @@ [ "~" "?" - "=>" ".." "..." ] @punctuation.special From 07dcf9b958cf3f6aa4022e40f9bdc6684a25f443 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 21:39:16 -0600 Subject: [PATCH 11/38] Specialize ternary operator --- queries/rescript/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 0aed017..3ca1299 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -220,7 +220,7 @@ "..." ] @punctuation.special -(ternary_expression ["?" ":"] @operator) +(ternary_expression ["?" ":"] @keyword.conditional.ternary) ; JSX ;---------- From 88d6a90b4109bfe4a4614a085282146578eb124e Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 21:52:40 -0600 Subject: [PATCH 12/38] Highlight function name in bindings --- queries/rescript/highlights.scm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 3ca1299..547f4f5 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -81,6 +81,11 @@ (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)) + ; Meta ;----- From b3ba6260034e214b28950630f6c7245912533881 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 21:52:49 -0600 Subject: [PATCH 13/38] Highlight function calls --- queries/rescript/highlights.scm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 547f4f5..d01db56 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -86,6 +86,22 @@ 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)) + ; Meta ;----- From 5479086e90dc0f4e1cf19de0398bf90d97e73d41 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Wed, 20 Mar 2024 21:57:09 -0600 Subject: [PATCH 14/38] Highlight members of records and modules --- queries/rescript/highlights.scm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index d01db56..ecf31f3 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -30,6 +30,13 @@ (member_expression (property_identifier) @property) (module_identifier) @module +(record_pattern + (value_identifier) @variable.member) + +(value_identifier_path + (module_identifier) + (value_identifier) @variable.member) + ; Parameters ;---------------- From 20f0b4abd15b3811fce4cf582ee6cbd9f098bb6f Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sat, 23 Mar 2024 21:47:51 -0600 Subject: [PATCH 15/38] Highlight unit as built-in constant --- queries/rescript/highlights.scm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index ecf31f3..46b49ed 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -18,6 +18,10 @@ (#any-of? @type.builtin "int" "char" "string" "float" "bool" "unit")) + +((unit) @constant.builtin + (#set! "priority" 105)) + [ (variant_identifier) (polyvar_identifier) From bfa3fae34dcd34313b72eb9feae3fe844a9f6838 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sat, 23 Mar 2024 21:49:34 -0600 Subject: [PATCH 16/38] Highlight labeled parameters names as properties --- queries/rescript/highlights.scm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 46b49ed..e5c555e 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -41,6 +41,10 @@ (module_identifier) (value_identifier) @variable.member) +(labeled_argument + label: (value_identifier) @property) + + ; Parameters ;---------------- From 668040311b5fd303e3208d8d89b962d7e9043a14 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 24 Mar 2024 11:24:20 -0600 Subject: [PATCH 17/38] Fix existing tests --- queries/rescript/highlights.scm | 14 +++++++++++--- test/highlight/decorators.res | 4 ++-- test/highlight/expressions.res | 22 +++++++++++----------- test/highlight/functions.res | 10 +++++----- test/highlight/literals.res | 26 +++++++++++++------------- test/highlight/modules.res | 20 ++++++++++---------- test/highlight/type_declarations.res | 8 ++++---- 7 files changed, 56 insertions(+), 48 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index e5c555e..57d5642 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -102,6 +102,17 @@ body: (function)) ; function calls + +; neovim and tree-sitter-cli handle conflicts differently: +; in tree-sitter-cli the first match wins, while in neovim the last match does. +; to get the desired result for `raise` in both, we put it before the general function call +; queries (for the CLI), but also add a priority metadata rule (for neovim). + +(call_expression + function: (value_identifier) @keyword.exception + (#set! "priority" 105) + (#eq? @keyword.exception "raise")) + (call_expression function: (value_identifier_path _ @@ -181,9 +192,6 @@ "catch" ] @keyword.exception -(call_expression - function: (value_identifier) @keyword.exception - (#eq? @keyword.exception "raise")) [ "for" 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..da660b7 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 diff --git a/test/highlight/functions.res b/test/highlight/functions.res index 59d4bc8..015a61f 100644 --- a/test/highlight/functions.res +++ b/test/highlight/functions.res @@ -1,12 +1,12 @@ let inc = n => n + 1 -// ^ parameter +// ^ variable.parameter // ^ punctuation.special let fn = (a, (b, c), {d, e}, [f, g]) => a + b + c + d + e + f + g -// ^ parameter -// ^ parameter -// ^ parameter -// ^ parameter +// ^ variable.parameter +// ^ variable.parameter +// ^ variable.parameter +// ^ variable.parameter let uncurry = (. u, .x) => (u, x) // ^ operator diff --git a/test/highlight/literals.res b/test/highlight/literals.res index fcbbe88..bd75abe 100644 --- a/test/highlight/literals.res +++ b/test/highlight/literals.res @@ -1,26 +1,26 @@ /**/ #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 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 From 08e1ecd22424bf68d01461e53368a48e70a9f965 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 24 Mar 2024 13:20:29 -0600 Subject: [PATCH 18/38] Fix pipe operator call highlighting to work with simple values too --- queries/rescript/highlights.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 57d5642..7308eb0 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -124,9 +124,11 @@ ; highlight the right-hand side of a pipe operator as a function call (pipe_expression _ - (value_identifier_path + [(value_identifier_path _ - (value_identifier) @function.call)) + (value_identifier) @function.call) + (value_identifier) @function.call]) + ; Meta ;----- From 9a7d2cc194b947e4f9180533ef33ee4779107096 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 24 Mar 2024 13:46:36 -0600 Subject: [PATCH 19/38] Add highlight tests for function names and calls --- test/highlight/expressions.res | 7 +++++++ test/highlight/functions.res | 1 + 2 files changed, 8 insertions(+) diff --git a/test/highlight/expressions.res b/test/highlight/expressions.res index da660b7..04e7841 100644 --- a/test/highlight/expressions.res +++ b/test/highlight/expressions.res @@ -55,3 +55,10 @@ let c = list{a, ...list{b}} // ^ type // ^ variable // ^ variable + +let x = fn() +// ^ function.call + +let y = x->M.f->f +// ^function.call +// ^function.call diff --git a/test/highlight/functions.res b/test/highlight/functions.res index 015a61f..3d34b22 100644 --- a/test/highlight/functions.res +++ b/test/highlight/functions.res @@ -1,6 +1,7 @@ let inc = n => n + 1 // ^ variable.parameter // ^ punctuation.special +// ^ function let fn = (a, (b, c), {d, e}, [f, g]) => a + b + c + d + e + f + g // ^ variable.parameter From 0c5f54450ef3fe58705a566139446e60c04efe39 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 24 Mar 2024 13:59:04 -0600 Subject: [PATCH 20/38] Add tests for module and record members --- test/highlight/expressions.res | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/highlight/expressions.res b/test/highlight/expressions.res index 04e7841..0c2799d 100644 --- a/test/highlight/expressions.res +++ b/test/highlight/expressions.res @@ -62,3 +62,9 @@ let x = fn() let y = x->M.f->f // ^function.call // ^function.call + +let v = M.v +// ^variable.member + +let {x} = y +// ^variable.member From d5bd57f32b90427e2bca76b2573b4be8d4d4e1d7 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 24 Mar 2024 14:02:45 -0600 Subject: [PATCH 21/38] Change record field expression to member --- queries/rescript/highlights.scm | 3 ++- test/highlight/expressions.res | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 7308eb0..364436e 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -31,9 +31,10 @@ (record_field (property_identifier) @property) (object (field (property_identifier) @property)) (object_type (field (property_identifier) @property)) -(member_expression (property_identifier) @property) (module_identifier) @module +(member_expression (property_identifier) @variable.member) + (record_pattern (value_identifier) @variable.member) diff --git a/test/highlight/expressions.res b/test/highlight/expressions.res index 0c2799d..066d0a6 100644 --- a/test/highlight/expressions.res +++ b/test/highlight/expressions.res @@ -68,3 +68,6 @@ let v = M.v let {x} = y // ^variable.member + +let x = y.x +// ^variable.member From 83f72094f1e68b0c64caefee4e005ccf85ff1369 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 24 Mar 2024 14:37:54 -0600 Subject: [PATCH 22/38] Add test for labeled argument as property --- test/highlight/expressions.res | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/highlight/expressions.res b/test/highlight/expressions.res index 066d0a6..dc407ca 100644 --- a/test/highlight/expressions.res +++ b/test/highlight/expressions.res @@ -71,3 +71,6 @@ let {x} = y let x = y.x // ^variable.member + +f(~a=b) +// ^property From 777ddf501507ff6ed948e1b6788e2131d4dc235d Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 24 Mar 2024 19:27:41 -0600 Subject: [PATCH 23/38] Add test for unit highlight --- test/highlight/expressions.res | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/highlight/expressions.res b/test/highlight/expressions.res index dc407ca..8258fba 100644 --- a/test/highlight/expressions.res +++ b/test/highlight/expressions.res @@ -72,5 +72,6 @@ let {x} = y let x = y.x // ^variable.member -f(~a=b) +f(~a=b, ()) // ^property +// ^constant.builtin From dc8abb8a2df04710f8e20812ad3c56427c7f5f1d Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 24 Mar 2024 19:51:35 -0600 Subject: [PATCH 24/38] Adapt to new tree-sitter last match wins --- queries/rescript/highlights.scm | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 364436e..a1b9ea9 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -104,16 +104,6 @@ ; function calls -; neovim and tree-sitter-cli handle conflicts differently: -; in tree-sitter-cli the first match wins, while in neovim the last match does. -; to get the desired result for `raise` in both, we put it before the general function call -; queries (for the CLI), but also add a priority metadata rule (for neovim). - -(call_expression - function: (value_identifier) @keyword.exception - (#set! "priority" 105) - (#eq? @keyword.exception "raise")) - (call_expression function: (value_identifier_path _ @@ -195,6 +185,9 @@ "catch" ] @keyword.exception +(call_expression + function: (value_identifier) @keyword.exception + (#eq? @keyword.exception "raise")) [ "for" From 81963091d96aee8ecd0ea23585db02002f39e067 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 24 Mar 2024 20:39:31 -0600 Subject: [PATCH 25/38] Move template highlight rule --- queries/rescript/highlights.scm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index a1b9ea9..6950285 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -60,9 +60,6 @@ (template_string) ] @string -(template_substitution - "${" @punctuation.special - "}" @punctuation.special) @embedded (character) @character (escape_sequence) @string.escape @@ -245,6 +242,10 @@ "]" ] @punctuation.bracket +(template_substitution + "${" @punctuation.special + "}" @punctuation.special) @embedded + (polyvar_type [ "[" From ac21b003f01a4ad6fc9d87c6a70a841d9aee28ea Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 13:43:02 -0600 Subject: [PATCH 26/38] Add string interpolation test --- test/highlight/literals.res | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/highlight/literals.res b/test/highlight/literals.res index bd75abe..0cad50c 100644 --- a/test/highlight/literals.res +++ b/test/highlight/literals.res @@ -24,3 +24,8 @@ /**/ '\\' // ^ string.escape + +/**/ `${hello}` +// ^ punctuation.special +// ^ punctuation.special +// ^ punctuation.special From bf62a2da060e5211d24f2e38aa2069e85c296f55 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 13:43:31 -0600 Subject: [PATCH 27/38] Remove member highlight as property --- queries/rescript/highlights.scm | 1 - 1 file changed, 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 6950285..973fca2 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -129,7 +129,6 @@ ; Misc ;----- -(subscript_expression index: (string) @property) (polyvar_type_pattern "#" @constructor) [ From 85a4f4113e7b4eb350e68e66504883b0ef987c4c Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 13:58:57 -0600 Subject: [PATCH 28/38] Change highlight of variable from module --- queries/rescript/highlights.scm | 2 +- test/highlight/expressions.res | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 973fca2..492ced7 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -40,7 +40,7 @@ (value_identifier_path (module_identifier) - (value_identifier) @variable.member) + (value_identifier) @variable) (labeled_argument label: (value_identifier) @property) diff --git a/test/highlight/expressions.res b/test/highlight/expressions.res index 8258fba..ac39698 100644 --- a/test/highlight/expressions.res +++ b/test/highlight/expressions.res @@ -64,7 +64,7 @@ let y = x->M.f->f // ^function.call let v = M.v -// ^variable.member +// ^variable let {x} = y // ^variable.member From 3a20909d0cb7a9c546787dd86d09e4e81298bb32 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 14:21:06 -0600 Subject: [PATCH 29/38] Change highlight of destructured variables --- queries/rescript/highlights.scm | 11 ++++++++--- test/highlight/expressions.res | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 492ced7..ffcfe0a 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -35,13 +35,18 @@ (member_expression (property_identifier) @variable.member) -(record_pattern - (value_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) @property) diff --git a/test/highlight/expressions.res b/test/highlight/expressions.res index ac39698..7c12587 100644 --- a/test/highlight/expressions.res +++ b/test/highlight/expressions.res @@ -67,7 +67,10 @@ let v = M.v // ^variable let {x} = y -// ^variable.member +// ^variable + +let {X.x} = y +// ^variable.member let x = y.x // ^variable.member From d5a3946b9a32199dcbe38a01c7e3d8966aadf582 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 18:21:53 -0600 Subject: [PATCH 30/38] Change highlight of labeled arguments --- queries/rescript/highlights.scm | 2 +- test/highlight/expressions.res | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index ffcfe0a..a423715 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -48,7 +48,7 @@ (value_identifier) @variable) (labeled_argument - label: (value_identifier) @property) + label: (value_identifier) @variable.parameter) ; Parameters diff --git a/test/highlight/expressions.res b/test/highlight/expressions.res index 7c12587..f9fce81 100644 --- a/test/highlight/expressions.res +++ b/test/highlight/expressions.res @@ -76,5 +76,5 @@ let x = y.x // ^variable.member f(~a=b, ()) -// ^property +// ^variable.parameter // ^constant.builtin From 1fe1bbdb11a45440302a4b3bc21f73f004a4ad3a Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 18:41:56 -0600 Subject: [PATCH 31/38] Fix highlight of variables in string interpolation --- queries/rescript/highlights.scm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index a423715..7443553 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) @@ -248,7 +251,7 @@ (template_substitution "${" @punctuation.special - "}" @punctuation.special) @embedded + "}" @punctuation.special) @none (polyvar_type [ From 996bde652fa77b9748713b114ca8217e0d743809 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 19:35:10 -0600 Subject: [PATCH 32/38] Fix parameter highlights --- queries/rescript/highlights.scm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 7443553..1c0300e 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -88,10 +88,9 @@ ;---------- ; parameter(s) in parens -[ - (parameter (value_identifier)) - (labeled_parameter (value_identifier)) -] @variable.parameter + +(parameter (value_identifier) @variable.parameter) +(labeled_parameter (value_identifier) @variable.parameter) ; single parameter with no parens (function parameter: (value_identifier) @variable.parameter) From 74f3f3a72d8703aa242320218980b12185ffd79c Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 19:35:46 -0600 Subject: [PATCH 33/38] Move "as" to keyword.operator --- queries/rescript/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 1c0300e..d18344d 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -145,7 +145,6 @@ [ - "as" "private" "mutable" "rec" @@ -158,6 +157,7 @@ [ "and" "with" + "as" ] @keyword.operator [ From 7473a296e4fdd68a4c2cfff2d3fefb11706a8d72 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 19:44:12 -0600 Subject: [PATCH 34/38] Move async/await to coroutine --- queries/rescript/highlights.scm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index d18344d..febda7d 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -171,7 +171,9 @@ "constraint" ] @keyword -((function "async" @keyword)) +(("await") @keyword.coroutine) + +((function "async" @keyword.coroutine)) (module_unpack "unpack" @keyword) From 736c0bb5eedfaacc04dbcac7d068b7cbf3421375 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 19:54:39 -0600 Subject: [PATCH 35/38] Fix test --- test/highlight/functions.res | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/highlight/functions.res b/test/highlight/functions.res index 3d34b22..153c38b 100644 --- a/test/highlight/functions.res +++ b/test/highlight/functions.res @@ -9,9 +9,5 @@ let fn = (a, (b, c), {d, e}, [f, g]) => a + b + c + d + e + f + g // ^ variable.parameter // ^ variable.parameter -let uncurry = (. u, .x) => (u, x) -// ^ operator -// ^ operator - let get = async (id) => id -// ^ keyword +// ^ keyword.coroutine From bc3b70786c591fc4c9cba6e63b03259ee32a7e12 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Sun, 26 May 2024 20:08:02 -0600 Subject: [PATCH 36/38] Add missing punctutation highlights --- queries/rescript/highlights.scm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index febda7d..ca7d829 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -206,6 +206,7 @@ "." "," "|" + ":" ] @punctuation.delimiter [ @@ -248,6 +249,8 @@ "}" "[" "]" + "<" + ">" ] @punctuation.bracket (template_substitution From f81c39dd995a9c6620c0b86819df39cc7acf83e6 Mon Sep 17 00:00:00 2001 From: Emilio Srougo Date: Mon, 24 Jun 2024 08:40:03 -0600 Subject: [PATCH 37/38] Remove metadata from unit highlight --- queries/rescript/highlights.scm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index ca7d829..783bc87 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -21,10 +21,6 @@ (#any-of? @type.builtin "int" "char" "string" "float" "bool" "unit")) - -((unit) @constant.builtin - (#set! "priority" 105)) - [ (variant_identifier) (polyvar_identifier) @@ -253,6 +249,8 @@ ">" ] @punctuation.bracket +(unit ["(" ")"] @constant.builtin) + (template_substitution "${" @punctuation.special "}" @punctuation.special) @none From e4bed23354c3d7ea41f2fc8ceabccd7b4008a145 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 24 Jul 2024 21:32:48 -0300 Subject: [PATCH 38/38] (true) and (false) as boolean --- queries/rescript/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/rescript/highlights.scm b/queries/rescript/highlights.scm index 783bc87..bc55504 100644 --- a/queries/rescript/highlights.scm +++ b/queries/rescript/highlights.scm @@ -74,7 +74,7 @@ [ (true) (false) -] @constant.builtin +] @boolean (number) @number (polyvar) @constructor