Skip to content

Commit

Permalink
feat(languages): rescript (#1616)
Browse files Browse the repository at this point in the history
* Add rescript language support

* cargo xtask docgen

* Add textobjects & file line ending

* Fix text objects & rerun docgen

* Fix textobjects queries
  • Loading branch information
Jared Ramirez authored Feb 6, 2022
1 parent 6c11708 commit f5b95be
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,7 @@
path = helix-syntax/languages/tree-sitter-twig
url = https://github.com/eirabben/tree-sitter-twig.git
shallow = true
[submodule "helix-syntax/languages/tree-sitter-rescript"]
path = helix-syntax/languages/tree-sitter-rescript
url = https://github.com/jaredramirez/tree-sitter-rescript
shallow = true
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
| python |||| `pylsp` |
| racket | | | | `racket` |
| regex || | | |
| rescript ||| | `rescript-language-server` |
| ruby || || `solargraph` |
| rust |||| `rust-analyzer` |
| scala || || `metals` |
Expand Down
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-rescript
Submodule tree-sitter-rescript added at 761eb9
11 changes: 11 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -602,3 +602,14 @@ scope = "source.iex"
injection-regex = "iex"
file-types = ["iex"]
roots = []

[[language]]
name = "rescript"
scope = "source.rescript"
injection-regex = "rescript"
file-types = ["res"]
roots = ["bsconfig.json"]
auto-format = true
comment-token = "//"
language-server = { command = "rescript-language-server", args = ["--stdio"] }
indent = { tab-width = 2, unit = " " }
179 changes: 179 additions & 0 deletions runtime/queries/rescript/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
(comment) @comment

; Identifiers
;------------

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

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

[
(variant_identifier)
(polyvar_identifier)
] @constant

(property_identifier) @variable.other.member
(module_identifier) @namespace

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

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

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

; String literals
;----------------

[
(string)
(template_string)
] @string

(template_substitution
"${" @punctuation.bracket
"}" @punctuation.bracket) @embedded

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

; Other literals
;---------------

[
(true)
(false)
] @constant.builtin

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

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

[
(formal_parameters (value_identifier))
(positional_parameter (value_identifier))
(labeled_parameter (value_identifier))
] @variable.parameter

(function parameter: (value_identifier) @variable.parameter)

; Meta
;-----

[
"@"
"@@"
(decorator_identifier)
] @label

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

; Misc
;-----

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

[
("include")
("open")
] @keyword

[
"as"
"export"
"external"
"let"
"module"
"mutable"
"private"
"rec"
"type"
"and"
] @keyword

[
"if"
"else"
"switch"
] @keyword

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

[
"."
","
"|"
] @punctuation.delimiter

[
"++"
"+"
"+."
"-"
"-."
"*"
"*."
"/"
"/."
"<"
"<="
"=="
"==="
"!"
"!="
"!=="
">"
">="
"&&"
"||"
"="
":="
"->"
"|>"
":>"
(uncurry)
] @operator

[
"("
")"
"{"
"}"
"["
"]"
] @punctuation.bracket

(polyvar_type
[
"["
"[>"
"[<"
"]"
] @punctuation.bracket)

[
"~"
"?"
"=>"
"..."
] @punctuation

(ternary_expression ["?" ":"] @operator)
8 changes: 8 additions & 0 deletions runtime/queries/rescript/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
((comment) @injection.content
(#set! injection.language "comment"))

((raw_js) @injection.content
(#set! injection.language "javascript"))

((raw_gql) @injection.content
(#set! injection.language "graphql"))
9 changes: 9 additions & 0 deletions runtime/queries/rescript/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; Classes (modules)
;------------------

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

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

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

0 comments on commit f5b95be

Please sign in to comment.