aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules4
-rw-r--r--book/src/generated/lang-support.md1
m---------helix-syntax/languages/tree-sitter-rescript0
-rw-r--r--languages.toml11
-rw-r--r--runtime/queries/rescript/highlights.scm179
-rw-r--r--runtime/queries/rescript/injections.scm8
-rw-r--r--runtime/queries/rescript/textobjects.scm9
7 files changed, 212 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules
index d35b0f33..55ed97b3 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -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
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index d10b56f1..64dab6d3 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -46,6 +46,7 @@
| python | ✓ | ✓ | ✓ | `pylsp` |
| racket | | | | `racket` |
| regex | ✓ | | | |
+| rescript | ✓ | ✓ | | `rescript-language-server` |
| ruby | ✓ | | ✓ | `solargraph` |
| rust | ✓ | ✓ | ✓ | `rust-analyzer` |
| scala | ✓ | | ✓ | `metals` |
diff --git a/helix-syntax/languages/tree-sitter-rescript b/helix-syntax/languages/tree-sitter-rescript
new file mode 160000
+Subproject 761eb9126b65e078b1b5770ac296b4af8870f93
diff --git a/languages.toml b/languages.toml
index 74c01da5..041d1564 100644
--- a/languages.toml
+++ b/languages.toml
@@ -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 = " " }
diff --git a/runtime/queries/rescript/highlights.scm b/runtime/queries/rescript/highlights.scm
new file mode 100644
index 00000000..b9ab8ea6
--- /dev/null
+++ b/runtime/queries/rescript/highlights.scm
@@ -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)
diff --git a/runtime/queries/rescript/injections.scm b/runtime/queries/rescript/injections.scm
new file mode 100644
index 00000000..201cce75
--- /dev/null
+++ b/runtime/queries/rescript/injections.scm
@@ -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"))
diff --git a/runtime/queries/rescript/textobjects.scm b/runtime/queries/rescript/textobjects.scm
new file mode 100644
index 00000000..7ee8cd1a
--- /dev/null
+++ b/runtime/queries/rescript/textobjects.scm
@@ -0,0 +1,9 @@
+; Classes (modules)
+;------------------
+
+(module_declaration definition: ((_) @class.inside)) @class.around
+
+; Functions
+;----------
+
+(function body: (_) @function.inside) @function.around