From 07968880e6a5a8287d316cd7c864f83769ab814d Mon Sep 17 00:00:00 2001 From: Freddie Gilbraith <75043775+FreddieGilbraith@users.noreply.github.com> Date: Wed, 20 Nov 2024 22:08:38 +0000 Subject: [PATCH] update to newest rescript treesitter library and queries (#11165) Co-authored-by: Michael Davis Co-authored-by: Freddie Ridell --- languages.toml | 2 +- runtime/queries/rescript/highlights.scm | 31 ++++++++++++---------- runtime/queries/rescript/injections.scm | 33 +++++++++++++++++++----- runtime/queries/rescript/locals.scm | 6 ++--- runtime/queries/rescript/textobjects.scm | 2 +- 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/languages.toml b/languages.toml index 0661d9c3e..93ea3bd04 100644 --- a/languages.toml +++ b/languages.toml @@ -1825,7 +1825,7 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "rescript" -source = { git = "https://github.com/jaredramirez/tree-sitter-rescript", rev = "467dcf99f68c47823d7b378779a6b282d7ef9782" } +source = { git = "https://github.com/rescript-lang/tree-sitter-rescript", rev = "5e2a44a9d886b0a509f5bfd0437d33b4871fbac5" } [[language]] name = "erlang" diff --git a/runtime/queries/rescript/highlights.scm b/runtime/queries/rescript/highlights.scm index ed41322b4..51d37b87c 100644 --- a/runtime/queries/rescript/highlights.scm +++ b/runtime/queries/rescript/highlights.scm @@ -10,11 +10,10 @@ [ (type_identifier) (unit_type) + (list) + (list_pattern) ] @type -(list ["list{" "}"] @type) -(list_pattern ["list{" "}"] @type) - [ (variant_identifier) (polyvar_identifier) @@ -72,14 +71,16 @@ ; single parameter with no parens (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) @variable.parameter))) +(parameter (array_pattern (value_identifier) @variable.parameter)) +(parameter (record_pattern (value_identifier) @variable.parameter)) + ; Meta ;----- -[ - "@" - "@@" - (decorator_identifier) -] @keyword.directive +(decorator_identifier) @keyword.directive (extension_identifier) @keyword ("%") @keyword @@ -87,7 +88,7 @@ ; Misc ;----- -; (subscript_expression index: (string) @attribute) +(subscript_expression index: (string) @attribute) (polyvar_type_pattern "#" @constant) [ @@ -101,18 +102,21 @@ "external" "let" "module" + "mutable" "private" "rec" "type" "and" "assert" - "async" "await" "with" - "unpack" -] @keyword.storage.type + "lazy" + "constraint" +] @keyword + +((function "async" @keyword.storage)) -"mutable" @keyword.storage.modifier +(module_unpack "unpack" @keyword) [ "if" @@ -169,6 +173,7 @@ "->" "|>" ":>" + "+=" (uncurry) ] @operator diff --git a/runtime/queries/rescript/injections.scm b/runtime/queries/rescript/injections.scm index 03e29b008..67f530d3b 100644 --- a/runtime/queries/rescript/injections.scm +++ b/runtime/queries/rescript/injections.scm @@ -1,8 +1,29 @@ -((comment) @injection.content - (#set! injection.language "comment")) +((comment) @injection.content (#set! injection.language "comment")) -((raw_js) @injection.content - (#set! injection.language "javascript")) +; %re +(extension_expression + (extension_identifier) @_name + (#eq? @_name "re") + (expression_statement (_) @injection.content (#set! injection.language "regex"))) + +; %raw +(extension_expression + (extension_identifier) @_name + (#eq? @_name "raw") + (expression_statement + (_ (_) @injection.content (#set! injection.language "javascript")))) + +; %graphql +(extension_expression + (extension_identifier) @_name + (#eq? @_name "graphql") + (expression_statement + (_ (_) @injection.content (#set! injection.language "graphql")))) + +; %relay +(extension_expression + (extension_identifier) @_name + (#eq? @_name "relay") + (expression_statement + (_ (_) @injection.content (#set! injection.language "graphql") ))) -((raw_gql) @injection.content - (#set! injection.language "graphql")) \ No newline at end of file diff --git a/runtime/queries/rescript/locals.scm b/runtime/queries/rescript/locals.scm index 1240ed160..4de73890e 100644 --- a/runtime/queries/rescript/locals.scm +++ b/runtime/queries/rescript/locals.scm @@ -1,7 +1,7 @@ (switch_expression) @local.scope -(if_expression) @local.scope ; Definitions ;------------ -(type_declaration) @local.defintion -(let_binding) @local.defintion +(type_declaration) @local.definition +(let_binding) @local.definition +(module_declaration) @local.definition diff --git a/runtime/queries/rescript/textobjects.scm b/runtime/queries/rescript/textobjects.scm index 4f1d8c53a..32c77b8f9 100644 --- a/runtime/queries/rescript/textobjects.scm +++ b/runtime/queries/rescript/textobjects.scm @@ -1,7 +1,7 @@ ; Classes (modules) ;------------------ -(module_declaration definition: ((_) @class.inside)) @class.around +(module_binding definition: ((_) @class.inside)) @class.around ; Blocks ;-------