Skip to content

Commit

Permalink
update to newest rescript treesitter library and queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Freddie Ridell authored and FreddieGilbraith committed Jul 14, 2024
1 parent c9b4840 commit 8335731
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 109 deletions.
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,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"
Expand Down
81 changes: 43 additions & 38 deletions runtime/queries/rescript/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,33 @@
;------------

; Escaped identifiers like \"+."
((value_identifier) @function.macro
(#match? @function.macro "^\\.*$"))
((value_identifier) @constant.macro
(#match? @constant.macro "^\\.*$"))

[
(type_identifier)
(unit_type)
(list)
(list_pattern)
] @type

(list ["list{" "}"] @type)
(list_pattern ["list{" "}"] @type)

[
(variant_identifier)
(polyvar_identifier)
] @constructor
] @constant

(record_type_field (property_identifier) @type)
(object_type (field (property_identifier) @type))
(record_field (property_identifier) @variable.other.member)
(object (field (property_identifier) @variable.other.member))
(member_expression (property_identifier) @variable.other.member)
(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

; Parameters
;----------------

(list_pattern (value_identifier) @variable.parameter)
(spread_pattern (value_identifier) @variable.parameter)
(list_pattern (value_identifier) @parameter)
(spread_pattern (value_identifier) @parameter)

; String literals
;----------------
Expand All @@ -46,7 +45,7 @@
"}" @punctuation.bracket) @embedded

(character) @string.special
(escape_sequence) @string.special
(escape_sequence) @string.escape

; Other literals
;---------------
Expand All @@ -56,7 +55,7 @@
(false)
] @constant.builtin

(number) @constant.numeric
(number) @number
(polyvar) @constant
(polyvar_string) @constant

Expand All @@ -67,52 +66,57 @@
[
(parameter (value_identifier))
(labeled_parameter (value_identifier))
] @variable.parameter
] @parameter

; single parameter with no parens
(function parameter: (value_identifier) @variable.parameter)
(function parameter: (value_identifier) @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))

; Meta
;-----

[
"@"
"@@"
(decorator_identifier)
] @keyword.directive
(decorator_identifier) @annotation

(extension_identifier) @keyword
("%") @keyword

; Misc
;-----

; (subscript_expression index: (string) @attribute)
(subscript_expression index: (string) @property)
(polyvar_type_pattern "#" @constant)

[
("include")
("open")
] @keyword.control.import
] @include

[
"as"
"export"
"external"
"let"
"module"
"mutable"
"private"
"rec"
"type"
"and"
"assert"
"async"
"await"
"with"
"unpack"
] @keyword.storage.type
"lazy"
"constraint"
] @keyword

"mutable" @keyword.storage.modifier
((function "async" @keyword))

(module_unpack "unpack" @keyword)

[
"if"
Expand All @@ -125,19 +129,19 @@
"exception"
"try"
"catch"
] @keyword.control.exception
] @exception

(call_expression
function: (value_identifier) @keyword.control.exception
(#eq? @keyword.control.exception "raise"))
function: (value_identifier) @exception
(#eq? @exception "raise"))

[
"for"
"in"
"to"
"downto"
"while"
] @keyword.control.conditional
] @repeat

[
"."
Expand Down Expand Up @@ -169,6 +173,7 @@
"->"
"|>"
":>"
"+="
(uncurry)
] @operator

Expand Down Expand Up @@ -207,14 +212,14 @@
;----------
(jsx_identifier) @tag
(jsx_element
open_tag: (jsx_opening_element ["<" ">"] @punctuation.special))
open_tag: (jsx_opening_element ["<" ">"] @tag.delimiter))
(jsx_element
close_tag: (jsx_closing_element ["<" "/" ">"] @punctuation.special))
(jsx_self_closing_element ["/" ">" "<"] @punctuation.special)
(jsx_fragment [">" "<" "/"] @punctuation.special)
(jsx_attribute (property_identifier) @attribute)
close_tag: (jsx_closing_element ["<" "/" ">"] @tag.delimiter))
(jsx_self_closing_element ["/" ">" "<"] @tag.delimiter)
(jsx_fragment [">" "<" "/"] @tag.delimiter)
(jsx_attribute (property_identifier) @tag.attribute)

; Error
;----------

(ERROR) @keyword.control.exception
(ERROR) @error
33 changes: 27 additions & 6 deletions runtime/queries/rescript/injections.scm
Original file line number Diff line number Diff line change
@@ -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"))
8 changes: 4 additions & 4 deletions runtime/queries/rescript/locals.scm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(switch_expression) @local.scope
(if_expression) @local.scope
(switch_expression) @scope

; Definitions
;------------
(type_declaration) @local.defintion
(let_binding) @local.defintion
(type_declaration) @definition.type
(let_binding) @definition.var
(module_declaration) @definition.namespace
Loading

0 comments on commit 8335731

Please sign in to comment.