Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade rescript tree sitter & highlights #4356

Merged
merged 3 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ indent = { tab-width = 2, unit = " " }

[[grammar]]
name = "rescript"
source = { git = "https://github.com/jaredramirez/tree-sitter-rescript", rev = "4cd7ba91696886fdaca086fb32b5fd8cc294a129" }
source = { git = "https://github.com/jaredramirez/tree-sitter-rescript", rev = "65609807c628477f3b94052e7ef895885ac51c3c" }

[[language]]
name = "erlang"
Expand Down
91 changes: 69 additions & 22 deletions runtime/queries/rescript/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,28 @@
[
(type_identifier)
(unit_type)
"list"
] @type


(list "list{" @type)
(list_pattern "list{" @type)

; To ensure that the closing curly bracket is the same color (scope) as the opening curly bracket
(list "}" @type (#set! "priority" 105))
(list_pattern "}" @type (#set! "priority" 105))
jaredramirez marked this conversation as resolved.
Show resolved Hide resolved

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

(property_identifier) @variable.other.member
(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)
(module_identifier) @namespace

(jsx_identifier) @tag
(jsx_attribute (property_identifier) @variable.parameter)

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

Expand All @@ -42,8 +50,8 @@
"${" @punctuation.bracket
"}" @punctuation.bracket) @embedded

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

; Other literals
;---------------
Expand All @@ -60,11 +68,13 @@
; Functions
;----------

; parameter(s) in parens
[
(formal_parameters (value_identifier))
(parameter (value_identifier))
(labeled_parameter (value_identifier))
] @variable.parameter

; single parameter with no parens
(function parameter: (value_identifier) @variable.parameter)

; Meta
Expand All @@ -74,47 +84,65 @@
"@"
"@@"
(decorator_identifier)
] @label
] @keyword.directive

(extension_identifier) @keyword
("%") @keyword
("%") @keyword.
jaredramirez marked this conversation as resolved.
Show resolved Hide resolved

; Misc
;-----

(subscript_expression index: (string) @variable.other.member)
; (subscript_expression index: (string) @attribute)
(polyvar_type_pattern "#" @constant)

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

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

"mutable" @keyword.storage.modifier

[
"if"
"else"
"switch"
] @keyword
"when"
] @keyword.control.conditional

[
"exception"
"try"
"catch"
"raise"
] @keyword
] @keyword.control.exception

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

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

[
"."
Expand All @@ -129,17 +157,15 @@
"-"
"-."
"*"
"**"
"*."
"/"
"/."
"<"
"<="
"=="
"==="
"!"
"!="
"!=="
">"
">="
"&&"
"||"
Expand All @@ -151,6 +177,10 @@
(uncurry)
] @operator

; Explicitly enclose these operators with binary_expression
; to avoid confusion with JSX tag delimiters
(binary_expression ["<" ">" "/"] @operator)

[
"("
")"
Expand All @@ -172,7 +202,24 @@
"~"
"?"
"=>"
".."
"..."
] @punctuation
] @punctuation.special

(ternary_expression ["?" ":"] @operator)

; JSX
;----------
(jsx_identifier) @tag
(jsx_element
open_tag: (jsx_opening_element ["<" ">"] @punctuation.special))
(jsx_element
close_tag: (jsx_closing_element ["<" "/" ">"] @punctuation.special))
(jsx_self_closing_element ["/" ">" "<"] @punctuation.special)
(jsx_fragment [">" "<" "/"] @punctuation.special)
(jsx_attribute (property_identifier) @attribute)

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

(ERROR) @keyword.control.exception
2 changes: 1 addition & 1 deletion runtime/queries/rescript/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
(#set! injection.language "javascript"))

((raw_gql) @injection.content
(#set! injection.language "graphql"))
(#set! injection.language "graphql"))
7 changes: 7 additions & 0 deletions runtime/queries/rescript/locals.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(switch_expression) @local.scope
(if_expression) @local.scope

; Definitions
;------------
(type_declaration) @local.defintion
(let_binding) @local.defintion
102 changes: 100 additions & 2 deletions runtime/queries/rescript/textobjects.scm
Original file line number Diff line number Diff line change
@@ -1,16 +1,114 @@
; Queries for nvim-treesitter/nvim-treesitter-textobjects
jaredramirez marked this conversation as resolved.
Show resolved Hide resolved
;--------------------------------------------------------

; Classes (modules)
;------------------

(module_declaration definition: ((_) @class.inside)) @class.around

; Blocks
;-------

(block (_) @function.inside) @function.around

; Functions
;----------

(function body: (_) @function.inside) @function.around

; Calls
;------

(call_expression arguments: ((_) @parameter.inside)) @parameter.around

; Comments
;---------

(comment) @comment.inside
(comment) @comment.around
jaredramirez marked this conversation as resolved.
Show resolved Hide resolved

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

(function parameter: (_) @parameter.inside @parameter.around)

(formal_parameters
","
. (_) @parameter.inside
@parameter.around)
(formal_parameters
. (_) @parameter.inside
. ","?
@parameter.around)

(arguments
"," @_arguments_start
. (_) @parameter.inside
@parameter.around)
(arguments
. (_) @parameter.inside
. ","?
@parameter.around)

(function_type_parameters
","
. (_) @parameter.inside
@parameter.around)
(function_type_parameters
. (_) @parameter.inside
. ","?
@parameter.around)

(functor_parameters
","
. (_) @parameter.inside
@parameter.around)
(functor_parameters
. (_) @parameter.inside
. ","?
@parameter.around)

(type_parameters
","
. (_) @parameter.inside
@parameter.around)
(type_parameters
. (_) @parameter.inside
. ","?
@parameter.around)

(type_arguments
","
. (_) @parameter.inside
@parameter.around)
(type_arguments
. (_) @parameter.inside
. ","?
@parameter.around)

(decorator_arguments
","
. (_) @parameter.inside
@parameter.around)
(decorator_arguments
. (_) @parameter.inside
. ","?
@parameter.around)

(variant_parameters
","
. (_) @parameter.inside
@parameter.around)
(variant_parameters
. (_) @parameter.inside
. ","?
@parameter.around)

(polyvar_parameters
","
. (_) @parameter.inside
@parameter.around)
(polyvar_parameters
. (_) @parameter.inside
. ","?
@parameter.around)

(comment)+ @comment.around