Skip to content

Commit d626b5e

Browse files
committed
feat: wasm, js and standalone vscode extension
1 parent 572c4a5 commit d626b5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+6023
-344
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22
members = ["crates/*", "fuzz"]
3+
exclude = ["crates/rhai-wasm"]
34

45
[profile.release]
56
lto = true

README.md

+21-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
- [Profiling](#profiling)
1111
- [Contributing](#contributing)
1212
- [Development Process](#development-process)
13-
- [Build and Install VSCode Extension](#build-and-install-vscode-extension)
14-
- [Build the Language Server](#build-the-language-server)
13+
- [Building and Installing the VSCode Extension](#building-and-installing-the-vscode-extension)
14+
- [Building the Rhai CLI](#building-the-rhai-cli)
1515
- [Debugging the Language Server](#debugging-the-language-server)
16+
- [Building the VSCode Extension](#building-the-vscode-extension)
1617

1718
# Rhai LSP
1819

@@ -23,7 +24,7 @@ It's incomplete and not recommended for general use yet, everything can be subje
2324
## Requirements
2425

2526
- Stable Rust toolchain (e.g. via [rustup](https://rustup.rs/))
26-
- yarn (for VS Code)
27+
- yarn 2 (for VS Code)
2728
- [vsce](https://www.npmjs.com/package/vsce) for VS Code extensions
2829

2930
## Project Structure
@@ -82,7 +83,7 @@ The documentation is still pretty much WIP (as everything else). All contributio
8283

8384
Currently the following steps are used to develop the project via vscode:
8485

85-
#### Build and Install VSCode Extension
86+
#### Building and Installing the VSCode Extension
8687

8788
Install the extension with the following:
8889
```sh
@@ -91,10 +92,10 @@ Install the extension with the following:
9192

9293
You only have to do this at the beginning or whenever you update the extension.
9394

94-
#### Build the Language Server
95+
#### Building the Rhai CLI
9596

9697
```sh
97-
cargo install --path crates/lsp --debug
98+
cargo install --path crates/rhai-cli --debug
9899
```
99100

100101
This will build and install the `rhai` executable globally that the vscode extension looks for.
@@ -104,3 +105,17 @@ After this step right now you have to manually kill the old running `rhai` execu
104105
#### Debugging the Language Server
105106

106107
The debugging process can consist of either strategically placed `tracing::info` statements that are visible in the VSCode debug console under `Rhai LSP`, or attaching a debugger to the running `rhai` process via [LLDB VSCode](https://marketplace.visualstudio.com/items?itemName=lanza.lldb-vscode). Both approaches deemed sufficient so far.
108+
109+
#### Building the VSCode Extension
110+
111+
The vscode extension relies on rhai-lsp compiled to WebAssembly via [`rhai-wasm`](./crates/rhai-wasm). There are several related [js libraries](./js) that are built on top of it.
112+
113+
Generally all you should need is `yarn` (2), and `vsce`, and the following single command:
114+
115+
```sh
116+
(cd editors/vscode && yarn && vsce package --no-yarn && code --install-extension *.vsix --force)
117+
```
118+
119+
If this fails, you will need to build each js package with `yarn build` individually.
120+
121+
If all that fails, make sure to perform your favourite JavaScript exorcism ritual or file an issue.

crates/rhai-common/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ tokio = { version = "1.19.2", features = [
2929
] }
3030
glob = "0.3.0"
3131
atty = "0.2.14"
32+
33+
[target.'cfg(target_arch = "wasm32")'.dependencies]
34+
tokio = { version = "1.19.2" }

crates/rhai-common/src/environment.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77
use tokio::io::{AsyncRead, AsyncWrite};
88
use url::Url;
99

10+
#[cfg(not(target_family = "wasm"))]
1011
pub mod native;
1112

1213
#[async_trait(?Send)]

crates/rhai-lsp/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ rhai-rowan = { version = "0.1.0", path = "../rhai-rowan" }
1313
ahash = "0.7.6"
1414
anyhow = "1.0.58"
1515
arc-swap = "1.5.0"
16-
async-ctrlc = { version = "1.2.0", features = ["stream"] }
1716
async-trait = "0.1.56"
1817
az = "1.2.0"
1918
clap = { version = "3.2.6", features = ["derive"] }

crates/rhai-lsp/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use std::sync::Arc;
1515
use rhai_common::environment::Environment;
1616
use lsp_async_stub::Server;
1717
use lsp_types::{notification, request};
18-
use world::{World, WorldState};
19-
18+
pub use world::{World, WorldState};
2019

2120
pub(crate) mod config;
2221
pub(crate) mod diagnostics;

crates/rhai-wasm/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

crates/rhai-wasm/Cargo.toml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[package]
2+
name = "rhai-wasm"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[lib]
9+
crate-type = ["cdylib"]
10+
11+
[dependencies]
12+
rhai-lsp = { version = "0.1.0", path = "../rhai-lsp" }
13+
rhai-common = { version = "0.1.0", path = "../rhai-common" }
14+
15+
anyhow = "1.0.57"
16+
async-trait = "0.1.56"
17+
clap = { version = "3.1.18", features = ["derive"] }
18+
console_error_panic_hook = "0.1.7"
19+
futures = "0.3.21"
20+
js-sys = "0.3.57"
21+
serde = { version = "1.0.137", features = ["derive"] }
22+
serde_json = "1.0.81"
23+
tokio = "1.19.2"
24+
tracing = "0.1.35"
25+
url = "2.2.2"
26+
wasm-bindgen = { version = "0.2.80", features = ["serde-serialize"] }
27+
wasm-bindgen-futures = "0.4.30"
28+
lsp-async-stub = "0.6.0"
29+
30+
[profile.release]
31+
opt-level = 's'
32+
lto = true

0 commit comments

Comments
 (0)