From e45f71fc7a518e8ba93e9e65633e661b6c8b6d15 Mon Sep 17 00:00:00 2001 From: Stefan Kopco Date: Sat, 21 Nov 2026 00:43:47 +0100 Subject: [PATCH 01/11] zed-rx: a Zed extension that declares .rx --- tooling/zed-rx/.gitignore | 3 +++ tooling/zed-rx/LICENSE | 21 +++++++++++++++++++ tooling/zed-rx/extension.toml | 12 +++++++++++ .../languages/reactivescript/config.toml | 19 +++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 tooling/zed-rx/.gitignore create mode 100644 tooling/zed-rx/LICENSE create mode 100644 tooling/zed-rx/extension.toml create mode 100644 tooling/zed-rx/languages/reactivescript/config.toml diff --git a/tooling/zed-rx/.gitignore b/tooling/zed-rx/.gitignore new file mode 100644 index 00000000..d3eb63e7 --- /dev/null +++ b/tooling/zed-rx/.gitignore @@ -0,0 +1,3 @@ +target/ +*.wasm +grammars/ diff --git a/tooling/zed-rx/LICENSE b/tooling/zed-rx/LICENSE new file mode 100644 index 00000000..d0e0b7d3 --- /dev/null +++ b/tooling/zed-rx/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Ryan Carniato + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/tooling/zed-rx/extension.toml b/tooling/zed-rx/extension.toml new file mode 100644 index 00000000..eec31b10 --- /dev/null +++ b/tooling/zed-rx/extension.toml @@ -0,0 +1,12 @@ +id = "reactivescript" +name = "ReactiveScript" +version = "0.1.0" +schema_version = 1 +authors = ["Ryan Carniato"] +description = "ReactiveScript (.rx, .d.rx): highlighting, and TypeScript's types, hover, go to definition, completion and errors through the .rx language server." +repository = "https://github.com/solidjs/reactivescript" + +[grammars.rx] +repository = "https://github.com/solidjs/reactivescript" +path = "tooling/tree-sitter-rx" +rev = "b4706142a696d24bc09911b195abc6a59e079b17" diff --git a/tooling/zed-rx/languages/reactivescript/config.toml b/tooling/zed-rx/languages/reactivescript/config.toml new file mode 100644 index 00000000..c583523e --- /dev/null +++ b/tooling/zed-rx/languages/reactivescript/config.toml @@ -0,0 +1,19 @@ +name = "ReactiveScript" +grammar = "rx" +# Zed matches a suffix against the file name's last dot segment, so "rx" covers .d.rx too. +path_suffixes = ["rx"] +code_fence_block_names = ["rx", "reactivescript"] +line_comments = ["// "] +block_comment = { start = "/*", prefix = "* ", end = "*/", tab_size = 1 } +wrap_characters = { start_prefix = "<", start_suffix = ">", end_prefix = "" } +autoclose_before = ";:.,=}])>" +brackets = [ + { start = "{", end = "}", close = true, newline = true }, + { start = "[", end = "]", close = true, newline = true }, + { start = "(", end = ")", close = true, newline = true }, + { start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] }, + { start = "`", end = "`", close = true, newline = false, not_in = ["string"] }, + { start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] }, +] +word_characters = ["#", "$"] +tab_size = 2 From 6b5124f1aa2599fd36d6aa05889a552df34d809b Mon Sep 17 00:00:00 2001 From: Stefan Kopco Date: Sat, 21 Nov 2026 00:53:15 +0100 Subject: [PATCH 02/11] zed-rx: highlights, outline, indents and the other queries --- .../languages/reactivescript/brackets.scm | 63 +++ .../languages/reactivescript/config.toml | 23 + .../languages/reactivescript/highlights.scm | 450 ++++++++++++++++++ .../languages/reactivescript/indents.scm | 44 ++ .../languages/reactivescript/injections.scm | 52 ++ .../languages/reactivescript/outline.scm | 139 ++++++ .../languages/reactivescript/overrides.scm | 34 ++ .../languages/reactivescript/textobjects.scm | 102 ++++ 8 files changed, 907 insertions(+) create mode 100644 tooling/zed-rx/languages/reactivescript/brackets.scm create mode 100644 tooling/zed-rx/languages/reactivescript/highlights.scm create mode 100644 tooling/zed-rx/languages/reactivescript/indents.scm create mode 100644 tooling/zed-rx/languages/reactivescript/injections.scm create mode 100644 tooling/zed-rx/languages/reactivescript/outline.scm create mode 100644 tooling/zed-rx/languages/reactivescript/overrides.scm create mode 100644 tooling/zed-rx/languages/reactivescript/textobjects.scm diff --git a/tooling/zed-rx/languages/reactivescript/brackets.scm b/tooling/zed-rx/languages/reactivescript/brackets.scm new file mode 100644 index 00000000..d63816ff --- /dev/null +++ b/tooling/zed-rx/languages/reactivescript/brackets.scm @@ -0,0 +1,63 @@ +; Matching brackets for ReactiveScript (.rx) in Zed. +; +; Written against the rx grammar (tooling/tree-sitter-rx, MIT) and its JSX and TypeScript node names, which are +; tree-sitter-javascript's and tree-sitter-typescript's (MIT). Each pattern pairs an opening token with the closing +; token of the same node. + +; Parentheses, square brackets and braces: calls, parameters, arrays, objects, statement blocks, view blocks, +; `{expr}` in markup, `effect (a, b)`, `rejects(E)` +("(" @open ")" @close) +("[" @open "]" @close) +("{" @open "}" @close) + +; `${ … }` in a template +(template_substitution + "${" @open + "}" @close) + +; Angle brackets of type arguments and type parameters +(type_arguments + "<" @open + ">" @close) +(type_parameters + "<" @open + ">" @close) + +; Markup tags: `

`, `

`, `` +(jsx_opening_element + "<" @open + ">" @close) +(jsx_closing_element + "" @close) +(jsx_self_closing_element + "<" @open + "/>" @close) + +; `` +(style_element + "<" @open + . + (identifier) + . + ">" @close) +(style_element + "" @close) + +; Quotes: matched, but left out of rainbow colouring +((string + "\"" @open + "\"" @close) + (#set! rainbow.exclude)) +((string + "'" @open + "'" @close) + (#set! rainbow.exclude)) +((template_string + "`" @open + "`" @close) + (#set! rainbow.exclude)) diff --git a/tooling/zed-rx/languages/reactivescript/config.toml b/tooling/zed-rx/languages/reactivescript/config.toml index c583523e..3afd9382 100644 --- a/tooling/zed-rx/languages/reactivescript/config.toml +++ b/tooling/zed-rx/languages/reactivescript/config.toml @@ -17,3 +17,26 @@ brackets = [ ] word_characters = ["#", "$"] tab_size = 2 + +# The rx grammar keeps TSX's JSX node names. +[jsx_tag_auto_close] +open_tag_node_name = "jsx_opening_element" +close_tag_node_name = "jsx_closing_element" +jsx_element_node_name = "jsx_element" +tag_name_node_name = "identifier" +tag_name_node_name_alternates = ["member_expression"] + +# The scopes overrides.scm captures. +[overrides.default] +linked_edit_characters = [".", "-"] + +[overrides.element] +line_comments = { remove = true } +block_comment = { start = "{/*", prefix = "", end = "*/}", tab_size = 1 } + +[overrides.string] +completion_query_characters = ["-", "."] +prefer_label_for_snippet = true + +[overrides.function_name_before_type_arguments] +prefer_label_for_snippet = true diff --git a/tooling/zed-rx/languages/reactivescript/highlights.scm b/tooling/zed-rx/languages/reactivescript/highlights.scm new file mode 100644 index 00000000..4d2c9f60 --- /dev/null +++ b/tooling/zed-rx/languages/reactivescript/highlights.scm @@ -0,0 +1,450 @@ +; Syntax highlighting for ReactiveScript (.rx) in Zed. +; +; Based on the rx grammar's own queries/highlights.scm, which in turn follows tree-sitter-javascript's highlights.scm +; and highlights-jsx.scm and tree-sitter-typescript's highlights.scm (all MIT). Capture names are the ones Zed's +; extension docs list for themes. When two patterns capture the same node the later one wins, so the file runs from +; the general (every identifier) to the specific (an equation's name, a JSX tag). + +; ============================================================ names, general + +(identifier) @variable + +(property_identifier) @property +(shorthand_property_identifier) @property +(private_property_identifier) @property + +; A capitalised name is most often a constructor or an error class; all-caps is a constant +((identifier) @constructor + (#match? @constructor "^[A-Z]")) + +([ + (identifier) + (shorthand_property_identifier) + (shorthand_property_identifier_pattern) +] @constant + (#match? @constant "^[A-Z_][A-Z0-9_]+$")) + +; Globals a browser program reads +((identifier) @variable.special + (#match? @variable.special "^(arguments|console|window|document|globalThis)$")) + +(this) @variable.special +(super) @variable.special + +; ============================================================ types + +(type_identifier) @type +(predefined_type) @type.builtin + +; ============================================================ functions + +(function_declaration + name: (identifier) @function) + +(function_expression + name: (identifier) @function) + +(method_definition + name: (property_identifier) @function) + +(pair + key: (property_identifier) @function + value: [(function_expression) (arrow_function) (fn_expression)]) + +(variable_declarator + name: (identifier) @function + value: [(function_expression) (arrow_function) (fn_expression)]) + +(call_expression + function: (identifier) @function) + +(call_expression + function: (member_expression + property: (property_identifier) @function)) + +; The prelude +(call_expression + function: (identifier) @function + (#any-of? @function "log" "onFlush" "onSettled")) + +; ============================================================ parameters + +(required_parameter + pattern: (identifier) @variable.parameter) + +(optional_parameter + pattern: (identifier) @variable.parameter) + +(required_parameter + pattern: (object_pattern + [ + (shorthand_property_identifier_pattern) @variable.parameter + (object_assignment_pattern + left: (shorthand_property_identifier_pattern) @variable.parameter) + (pair_pattern + value: (identifier) @variable.parameter) + ])) + +(arrow_function + parameter: (identifier) @variable.parameter) + +(for_block + name: (identifier) @variable.parameter) + +(errored_block + parameter: (identifier) @variable.parameter) + +(catch_expression + parameter: (identifier) @variable.parameter) + +(catch_clause + parameter: (identifier) @variable.parameter) + +; ============================================================ literals + +(comment) @comment + +((comment) @comment.doc + (#match? @comment.doc "^/\\*\\*")) + +(string) @string +(template_string) @string +(escape_sequence) @string.escape +(regex) @string.regex +(number) @number + +[ + (true) + (false) +] @boolean + +[ + (null) + (undefined) +] @constant.builtin + +; ============================================================ punctuation and operators + +[ + ";" + "," + "." + ":" + (optional_chain) +] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(template_substitution + "${" @punctuation.special + "}" @punctuation.special) @embedded + +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) + +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) + +[ + "+" + "-" + "*" + "/" + "%" + "**" + "++" + "--" + "=" + "==" + "===" + "!=" + "!==" + "<" + "<=" + ">" + ">=" + "<<" + ">>" + ">>>" + "!" + "~" + "^" + "&" + "|" + "&&" + "||" + "??" + "=>" + "..." + "?" + "->" +] @operator + +; ============================================================ keywords (JavaScript, TypeScript) + +[ + "as" + "async" + "await" + "break" + "case" + "catch" + "class" + "const" + "continue" + "debugger" + "default" + "delete" + "do" + "else" + "export" + "extends" + "finally" + "for" + "from" + "function" + "get" + "if" + "import" + "in" + "instanceof" + "let" + "new" + "of" + "return" + "set" + "static" + "switch" + "target" + "throw" + "try" + "typeof" + "var" + "void" + "while" + "with" + "yield" + "abstract" + "declare" + "enum" + "implements" + "interface" + "keyof" + "namespace" + "private" + "protected" + "public" + "readonly" + "override" + "satisfies" + "type" + "is" + "infer" +] @keyword + +; ============================================================ keywords (ReactiveScript) + +[ + "source" + "component" + "action" + "effect" + "fn" + "context" + "provide" + "use" + "error" + "server" + "client" + "key" + "fails" + "rejects" + "instantiates" + "guess" + "refresh" + "affects" + "loading" + "errored" + "fallback" + "on" + "portal" + "to" + "latest" + "peek" + "pre" + "pending?" + "draft" +] @keyword + +[ + (side) + (pure) + (deferred) + (ref_modifier) +] @keyword + +; `await* stream` +(await_expression + "*" @keyword) + +; `:=` writes a source (or seeds one) +":=" @keyword.operator + +; ============================================================ ReactiveScript declarations + +; A source is state: its name, and the root of every write or guess, stand out +(source_declaration + name: (identifier) @variable.special) + +(write_statement + target: [ + (identifier) @variable.special + (_ object: (identifier) @variable.special) + (_ object: (_ object: (identifier) @variable.special)) + (_ object: (_ object: (_ object: (identifier) @variable.special))) + ]) + +(guess_statement + target: [ + (identifier) @variable.special + (_ object: (identifier) @variable.special) + (_ object: (_ object: (identifier) @variable.special)) + (_ object: (_ object: (_ object: (identifier) @variable.special))) + ]) + +(refresh_statement + name: (identifier) @variable.special) + +(affects_statement + name: (identifier) @variable.special) + +(pre_expression + name: (identifier) @variable.special) + +; An equation is a derived value, named like a constant; so is each name a destructuring equation binds +(equation + name: (identifier) @constant) + +(equation + name: (object_pattern + [ + (shorthand_property_identifier_pattern) @constant + (pair_pattern + value: (identifier) @constant) + (object_assignment_pattern + left: (shorthand_property_identifier_pattern) @constant) + ])) + +(equation + name: (array_pattern + (identifier) @constant)) + +; Contexts +(context_declaration + name: (identifier) @constant) + +(provide_declaration + name: (identifier) @constant) + +(use_expression + name: (identifier) @constant) + +(key_clause + name: (identifier) @property) + +; Callables +(fn_declaration + name: (identifier) @function) + +(fn_signature + name: (identifier) @function) + +(server_function_declaration + name: (identifier) @function) + +(action_declaration + name: (identifier) @function) + +(component_declaration + name: (identifier) @function) + +(error_declaration + name: (type_identifier) @type) + +; An effect's inputs, `$0` … `$n` +((identifier) @variable.special + (#match? @variable.special "^\\$[0-9]+$")) + +; ============================================================ markup + +(jsx_attribute + (property_identifier) @attribute) + +; An HTML tag is a tag; a capitalised one is a component, coloured as a type +(jsx_opening_element + name: (identifier) @tag) +(jsx_closing_element + name: (identifier) @tag) +(jsx_self_closing_element + name: (identifier) @tag) + +(jsx_opening_element + name: (identifier) @type + (#match? @type "^[A-Z]")) +(jsx_closing_element + name: (identifier) @type + (#match? @type "^[A-Z]")) +(jsx_self_closing_element + name: (identifier) @type + (#match? @type "^[A-Z]")) + +; ``: the namespace is a variable, the last part the component +(jsx_opening_element + name: (member_expression + property: (property_identifier) @type)) +(jsx_closing_element + name: (member_expression + property: (property_identifier) @type)) +(jsx_self_closing_element + name: (member_expression + property: (property_identifier) @type)) + +(jsx_opening_element + [ + "<" + ">" + ] @punctuation.bracket) +(jsx_closing_element + [ + "" + ] @punctuation.bracket) +(jsx_self_closing_element + [ + "<" + "/>" + ] @punctuation.bracket) + +; `` +(style_element + (identifier) @tag) + +(style_element + [ + "<" + ">" + "" @end) @indent +(jsx_self_closing_element "/>" @end) @indent + +; A `