diff --git a/.github/workflows/zed.yml b/.github/workflows/zed.yml new file mode 100644 index 00000000..cdf5e722 --- /dev/null +++ b/.github/workflows/zed.yml @@ -0,0 +1,38 @@ +# The Zed extension (tooling/zed-rx): the extension builds for the target Zed loads, and its queries run on the +# grammar extension.toml pins. A query naming a node that grammar does not have stops Zed loading the language. +name: zed + +on: + push: + branches: [main] + paths: ["tooling/zed-rx/**", "examples/*.rx", ".github/workflows/zed.yml"] + pull_request: + paths: ["tooling/zed-rx/**", "examples/*.rx", ".github/workflows/zed.yml"] + workflow_dispatch: + +jobs: + extension: + runs-on: ubuntu-latest + defaults: + run: + working-directory: tooling/zed-rx + steps: + - uses: actions/checkout@v5 + - uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-wasip2 + components: clippy, rustfmt + - uses: Swatinem/rust-cache@v2 + with: + workspaces: tooling/zed-rx + - run: cargo fmt --check + - run: cargo clippy --release --target wasm32-wasip2 -- -D warnings + - run: cargo build --release --target wasm32-wasip2 + - uses: pnpm/action-setup@v4 + with: + version: 11.1.1 # as editor.yml + - uses: actions/setup-node@v5 + with: + node-version: 22 + - name: Queries, on the pinned grammar + run: ./check-queries.sh diff --git a/tooling/rx-language-server/README.md b/tooling/rx-language-server/README.md index 4eb74fa1..6f4ef29a 100644 --- a/tooling/rx-language-server/README.md +++ b/tooling/rx-language-server/README.md @@ -74,7 +74,9 @@ vim.lsp.config("rx", { vim.lsp.enable("rx") ``` -Neovim has no `.rx` grammar yet; the server's semantic tokens color names. +For highlighting, install the tree-sitter grammar in +[`../tree-sitter-rx`](../tree-sitter-rx) as the parser for `reactivescript`; +without it, the server's semantic tokens color names. **Helix**, in `languages.toml`: @@ -98,8 +100,9 @@ language server with the command map the file name pattern `*.rx` to it, and add the `tooling/vscode-rx` folder under Settings › Editor › TextMate Bundles for highlighting. -**Zed** needs an extension of its own (a Zed extension declares the language -and starts the server); there isn't one yet. +**Zed**: the extension in [`../zed-rx`](../zed-rx), which installs this server +from npm and highlights with the tree-sitter grammar in +[`../tree-sitter-rx`](../tree-sitter-rx). The `/path/to/reactivescript` paths are a checkout of this repository; with the npm package, the command is `npx @reactivescript/language-server --stdio` 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/Cargo.lock b/tooling/zed-rx/Cargo.lock new file mode 100644 index 00000000..7a99c139 --- /dev/null +++ b/tooling/zed-rx/Cargo.lock @@ -0,0 +1,845 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "auditable-serde" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7bf8143dfc3c0258df908843e169b5cc5fcf76c7718bd66135ef4a9cd558c5" +dependencies = [ + "semver", + "serde", + "serde_json", + "topological-sort", +] + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "crc32fast" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "flate2" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4" +dependencies = [ + "crc32fast", + "miniz_oxide", + "zlib-rs", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "icu_collections" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404a3b8c486f205c87fe7f23ab6894d84a4ad76d6e4671ae1981ba7def87c599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc" + +[[package]] +name = "icu_properties" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ea83d991c56158f7cf898bf86436c1dfe7c07ee82fe88951f2695c9f37a379f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98f29af82d02b163fe50161388350e743bb3107cc8e8c2f7314cb505faddfcf" + +[[package]] +name = "icu_provider" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + +[[package]] +name = "itoa" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn 2.0.119", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59" + +[[package]] +name = "spdx" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e17e880bafaeb362a7b751ec46bdc5b61445a188f80e0606e68167cd540fa3" +dependencies = [ + "smallvec", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "tinystr" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "topological-sort" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3bd9d3e571c26fcce9d033b87ea5ab061b8d2ffe9b7a5675d810d68f03edf0" +dependencies = [ + "utf_types", +] + +[[package]] +name = "utf_types" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6" + +[[package]] +name = "wasm-encoder" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80bb72f02e7fbf07183443b27b0f3d4144abf8c114189f2e088ed95b696a7822" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce1ef0faabbbba6674e97a56bee857ccddf942785a336c8b47b42373c922a91d" +dependencies = [ + "anyhow", + "auditable-serde", + "flate2", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "url", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f51cad774fb3c9461ab9bccc9c62dfb7388397b5deda31bf40e8108ccd678b2" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10fb6648689b3929d56bbc7eb1acf70c9a42a29eb5358c67c10f54dbd5d695de" +dependencies = [ + "wit-bindgen-rt", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92fa781d4f2ff6d3f27f3cc9b74a73327b31ca0dc4a3ef25a0ce2983e0e5af9b" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db52a11d4dfb0a59f194c064055794ee6564eb1ced88c25da2cf76e50c5621" +dependencies = [ + "bitflags", + "futures", + "once_cell", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d0809dc5ba19e2e98661bf32fc0addc5a3ca5bf3a6a7083aa6ba484085ff3ce" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn 2.0.119", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad19eec017904e04c60719592a803ee5da76cb51c81e3f6fbf9457f59db49799" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.119", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "635c3adc595422cbf2341a17fb73a319669cc8d33deed3a48368a841df86b676" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddf445ed5157046e4baf56f9138c124a0824d4d1657e7204d71886ad8ce2fc11" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zed-rx" +version = "0.1.0" +dependencies = [ + "zed_extension_api", +] + +[[package]] +name = "zed_extension_api" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0729d50b4ca0a7e28e590bbe32e3ca0194d97ef654961451a424c661a366fca0" +dependencies = [ + "serde", + "serde_json", + "wit-bindgen", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "zlib-rs" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/tooling/zed-rx/Cargo.toml b/tooling/zed-rx/Cargo.toml new file mode 100644 index 00000000..7eef9950 --- /dev/null +++ b/tooling/zed-rx/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "zed-rx" +version = "0.1.0" +edition = "2021" +publish = false +license = "MIT" + +[lib] +path = "src/lib.rs" +crate-type = ["cdylib"] + +[dependencies] +zed_extension_api = "0.7.0" 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/README.md b/tooling/zed-rx/README.md new file mode 100644 index 00000000..1cf8ebc4 --- /dev/null +++ b/tooling/zed-rx/README.md @@ -0,0 +1,115 @@ +# ReactiveScript for Zed + +Highlighting for `.rx` and `.d.rx` from a Tree-sitter grammar +([`../tree-sitter-rx`](../tree-sitter-rx)), and, through the `.rx` language server +([`../rx-language-server`](../rx-language-server)), TypeScript's hover, go to +definition, references, rename, completion and type errors, plus the +compiler's own diagnostics. ` ```rx ` and ` ```reactivescript ` blocks in +Markdown use the same language. + +The extension installs `@reactivescript/language-server` from npm (and updates it +when a newer release exists; offline it keeps the installed copy) and runs it +with Zed's Node over stdio. + +The project needs a `tsconfig.json` with Solid's JSX (`"jsx": "preserve"`, +`"jsxImportSource": "@solidjs/web"`) and `@solidjs/web` in its `node_modules`; +the server writes the projection's prelude to `node_modules/.reactivescript/`. +It uses the worktree's `node_modules/typescript`, else its own TypeScript. + +## Installing as a dev extension + +Run **zed: install dev extension** in the command palette and pick this folder +(`tooling/zed-rx`). Zed needs Rust (via rustup) to build the extension, and +fetches and compiles the grammar named in `extension.toml`. For local work, +point `[grammars.rx]`'s `repository` at a checkout with the grammar committed +(`file:///path/to/reactivescript`) and `rev` at that commit. + +## Working on the extension + +Before opening Zed, from this folder: + +```sh +cargo fmt --check +cargo clippy --release --target wasm32-wasip2 -- -D warnings +cargo build --release --target wasm32-wasip2 # rustup target add wasm32-wasip2 +./check-queries.sh # needs pnpm +``` + +`check-queries.sh` runs every query in `languages/reactivescript` over +`examples/*.rx`, on the grammar `extension.toml` pins. A query that names a +node the grammar does not have stops Zed loading the language at all, and Zed +only says so in its log. For a grammar change that is not pinned yet, check +against the working tree: `GRAMMAR=../tree-sitter-rx ./check-queries.sh`. CI +runs all four (`.github/workflows/zed.yml`). + +Then in Zed: + +- After a change, press **Rebuild** on the extension's row in + **zed: extensions**. Queries and `config.toml` are read again, and + `src/lib.rs` is recompiled. +- **zed: open log** shows a query or grammar that failed to load, and a failed + npm install. `zed --foreground` from a terminal prints more. +- **dev: open language server logs** shows how the server was started (its + command, arguments and `RXC`) and what it printed. +- **dev: open syntax tree view** shows the node under the cursor, which is what + a query pattern has to name. + +Worth trying by hand, since no check covers them: type `
` in a component +and see `
` appear; a `/** */` comment and a `//` comment keep their own +colours; `css` and `styled` templates are highlighted as CSS; the outline lists +components, sources and equations. + +## Settings + +All under `lsp.rx-language-server` in Zed's `settings.json`: + +```json +{ + "lsp": { + "rx-language-server": { + "settings": { + "rxc": { "path": "/path/to/reactivescript/compiler/target/release/rxc" }, + "typescript": { "tsdk": "/path/to/project/node_modules/typescript/lib" } + } + } + } +} +``` + +- `settings.rxc.path`: an `rxc` binary for the server to run per request + instead of its bundled WebAssembly build (sets `RXC`). +- `settings.typescript.tsdk`: TypeScript's `lib` folder. Unset: the worktree's + `node_modules/typescript/lib` if there is one (the worktree root only, not a + parent workspace's), else the server's own. +- `initialization_options`: merged over what the extension sends + (`{ "typescript": { "tsdk": … } }`). + +To run another server instead of the npm package, such as this repository's, +set `binary`. Zed then starts that command itself, without the extension: it +adds no `--stdio`, does not run a `.js` file with its Node, and does not read +`settings.rxc.path`, so name all three: + +```json +{ + "lsp": { + "rx-language-server": { + "binary": { + "path": "node", + "arguments": ["/path/to/reactivescript/tooling/rx-language-server/bin/server.js", "--stdio"], + "env": { "RXC": "/path/to/reactivescript/compiler/target/release/rxc" } + } + } + } +} +``` + +`binary.env` without a `path` is added to the npm server's environment. +`binary.arguments` without a `path` replaces the extension's arguments (the +server's path and `--stdio`), so set it only together with a `path`. + +The server's semantic tokens only show once Zed asks for them; they are off by +default: + +```json +{ "languages": { "ReactiveScript": { "semantic_tokens": "combined" } } } +``` diff --git a/tooling/zed-rx/check-queries.sh b/tooling/zed-rx/check-queries.sh new file mode 100755 index 00000000..96be68ac --- /dev/null +++ b/tooling/zed-rx/check-queries.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# Runs every query in languages/reactivescript over examples/*.rx. A query that names a node or field the grammar +# does not have stops Zed loading the language at all, and Zed only says so in its log. +# +# The grammar is the one extension.toml pins, since that is what Zed compiles: its commit is unpacked into +# target/grammar, fetched from the repository extension.toml names when this checkout does not have it (CI's never +# does, so there the pin is also checked to be a commit that repository has). +# +# GRAMMAR=../tree-sitter-rx ./check-queries.sh checks against a grammar folder instead (relative to this folder), +# for a grammar change that is not pinned yet. +set -eu +cd "$(dirname "$0")" +here=$(pwd) + +if [ -z "${GRAMMAR:-}" ]; then + pin() { sed -n "/^\[grammars\.rx\]/,\$ s/^$1 = \"\(.*\)\"/\1/p" extension.toml; } + repository=$(pin repository) + path=$(pin path) + rev=$(pin rev) + git cat-file -e "$rev^{commit}" 2>/dev/null || git fetch --quiet --depth 1 "$repository" "$rev" + rm -rf target/grammar + mkdir -p target/grammar + # -m: files dated now, so tree-sitter does not reuse a parser it built from another copy of the grammar + # From the repository's root: in a subfolder, git archive only writes what lies under that subfolder. + git -C "$(git rev-parse --show-toplevel)" archive "$rev:$path" | tar -xmf - -C target/grammar + GRAMMAR=target/grammar + echo "grammar: $repository at $rev" +else + echo "grammar: $GRAMMAR" +fi + +# A config of our own, so tree-sitter does not read the user's and does not warn that no parser directories are +# configured. The folder it names stays empty: the grammar is the current directory. +mkdir -p "$here/target/tree-sitter/parsers" +config="$here/target/tree-sitter/config.json" +printf '{ "parser-directories": ["%s"] }\n' "$here/target/tree-sitter/parsers" > "$config" + +cd "$GRAMMAR" +pnpm install --frozen-lockfile --silent +for query in "$here"/languages/reactivescript/*.scm; do + echo "$(basename "$query")" + pnpm exec tree-sitter query --config-path "$config" "$query" "$here"/../../examples/*.rx > /dev/null +done diff --git a/tooling/zed-rx/extension.toml b/tooling/zed-rx/extension.toml new file mode 100644 index 00000000..4e4d508a --- /dev/null +++ b/tooling/zed-rx/extension.toml @@ -0,0 +1,19 @@ +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" + +[language_servers.rx-language-server] +name = "ReactiveScript Language Server" +languages = ["ReactiveScript"] + +[language_servers.rx-language-server.language_ids] +"ReactiveScript" = "reactivescript" + +[grammars.rx] +repository = "https://github.com/solidjs/reactivescript" +path = "tooling/tree-sitter-rx" +rev = "b4706142a696d24bc09911b195abc6a59e079b17" 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 new file mode 100644 index 00000000..c5dbf46d --- /dev/null +++ b/tooling/zed-rx/languages/reactivescript/config.toml @@ -0,0 +1,43 @@ +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", "comment"] }, + { start = "`", end = "`", close = true, newline = false, not_in = ["string"] }, + { start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] }, +] +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..021df310 --- /dev/null +++ b/tooling/zed-rx/languages/reactivescript/highlights.scm @@ -0,0 +1,482 @@ +; 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. A theme without `function.builtin` styles it as `function`. +(call_expression + function: (identifier) @function.builtin + (#any-of? @function.builtin "log" "onFlush" "onSettled")) + +; ============================================================ parameters + +(required_parameter + pattern: (identifier) @variable.parameter) + +(optional_parameter + pattern: (identifier) @variable.parameter) + +; A destructured parameter: `{ a, b = 1, c: d }` and `[a, b = 1]` +(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) + ])) + +(optional_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) + ])) + +(required_parameter + pattern: (array_pattern + [ + (identifier) @variable.parameter + (assignment_pattern + left: (identifier) @variable.parameter) + ])) + +(optional_parameter + pattern: (array_pattern + [ + (identifier) @variable.parameter + (assignment_pattern + left: (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 + +; As injections.scm: `/**/` and a `/***` banner are plain comments +((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 + +[ + "+" + "-" + "*" + "/" + "%" + "**" + "++" + "--" + "=" + "==" + "===" + "!=" + "!==" + "<" + "<=" + ">" + ">=" + "<<" + ">>" + ">>>" + "!" + "~" + "^" + "&" + "|" + "&&" + "||" + "??" + "=>" + "..." + "?" + "->" +] @operator + +; After the operators: a generic's angle brackets are brackets, not comparisons +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) + +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) + +; ============================================================ 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. A query cannot recurse, so the root +; is found up to four members deep (`a.b.c.d.e := …`); a deeper target's root stays a plain variable. +(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))) + (_ object: (_ 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))) + (_ object: (_ 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 `