Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add noir_lsp_wasm as a WASI implementation of the LSP #2769

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7d2280f
feat: Add noir_lsp_wasm as a WASI implementation of the LSP
phated Sep 20, 2023
5836927
align rustix version with async-lsp
phated Sep 21, 2023
73fd403
upgrade rust toolchain to build WASI correctly
phated Sep 21, 2023
733d824
regen lock
phated Sep 21, 2023
23f8f49
normalize the vscode-test-web scheme
phated Sep 21, 2023
05b2af6
msrv to 1.67.0
phated Sep 21, 2023
4781f10
Merge branch 'master' into phated/lsp-wasm
TomAFrench Sep 29, 2023
abd0ec0
chore: clippy
TomAFrench Sep 29, 2023
e1c37ad
Merge branch 'master' into phated/lsp-wasm
TomAFrench Sep 29, 2023
420e25e
chore: move dependencies down into `noir_lsp_wasm`
TomAFrench Sep 29, 2023
859423e
Merge branch 'master' into phated/lsp-wasm
TomAFrench Sep 29, 2023
7d31a7a
chore: remove unused dependencies
TomAFrench Sep 29, 2023
4901267
chore: push stdio implementation upstream
TomAFrench Sep 29, 2023
627c390
Merge branch 'master' into phated/lsp-wasm
TomAFrench Sep 29, 2023
b7997e3
Merge branch 'master' into phated/lsp-wasm
TomAFrench Sep 29, 2023
43ec9dc
Merge branch 'master' into phated/lsp-wasm
TomAFrench Oct 18, 2023
c584fdd
Merge branch 'master' into phated/lsp-wasm
TomAFrench Oct 25, 2023
02f58c7
Merge branch 'master' into phated/lsp-wasm
TomAFrench Oct 31, 2023
10561d5
chore: fix `rust-version` field
TomAFrench Oct 31, 2023
b3de1bf
chore: fix merge
TomAFrench Oct 31, 2023
1a9a5b4
chore: enforce consistent version on noir_lsp_wasm
TomAFrench Oct 31, 2023
43a15b7
chore: use upstream async-lsp
TomAFrench Oct 31, 2023
c0f8f67
Merge branch 'master' into phated/lsp-wasm
TomAFrench Nov 2, 2023
7337352
Merge branch 'master' into phated/lsp-wasm
TomAFrench Nov 2, 2023
a8a6fc2
Merge branch 'master' into phated/lsp-wasm
TomAFrench Nov 14, 2023
88b44e8
Merge branch 'master' into phated/lsp-wasm
TomAFrench Nov 17, 2023
a1a4310
chore: remove unused patch
TomAFrench Nov 17, 2023
3cd3da0
Merge branch 'master' into phated/lsp-wasm
TomAFrench Jan 12, 2024
73a26a1
Merge branch 'master' into phated/lsp-wasm
TomAFrench Apr 21, 2024
389b7a0
chore: fix build
TomAFrench Apr 21, 2024
ee07c58
chore: fix CI
TomAFrench Apr 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
timeout-minutes: 30
env:
RUSTFLAGS: -Dwarnings

strategy:
fail-fast: false
matrix:
Expand All @@ -32,7 +32,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.66.0
uses: dtolnay/rust-toolchain@1.67.0
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
with:
targets: ${{ matrix.target }}
components: clippy, rustfmt
Expand All @@ -53,7 +53,7 @@ jobs:
name: eslint
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx$(sw_vers -productVersion) --show-sdk-platform-version)" >> $GITHUB_ENV

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.66.0
uses: dtolnay/rust-toolchain@1.67.0
with:
targets: ${{ matrix.target }}

Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
- name: Test built artifact
if: matrix.target == 'x86_64-apple-darwin'
run: |
cp ./target/${{ matrix.target }}/release/nargo ~/.cargo/bin/
cp ./target/${{ matrix.target }}/release/nargo ~/.cargo/bin/
yarn workspace release-tests test

- name: Upload binaries to release tag
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
ref: ${{ inputs.tag || env.GITHUB_REF }}

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.66.0
uses: dtolnay/rust-toolchain@1.67.0
with:
targets: ${{ matrix.target }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.66.0
uses: dtolnay/rust-toolchain@1.67.0
with:
targets: ${{ matrix.target }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.66.0
uses: dtolnay/rust-toolchain@1.67.0

- uses: Swatinem/rust-cache@v2
with:
Expand Down Expand Up @@ -143,7 +143,7 @@ jobs:
cp -r ./compiler/wasm/downloaded/nodejs ./compiler/wasm
cp -r ./compiler/wasm/downloaded/web ./compiler/wasm
yarn workspace @noir-lang/source-resolver build

- name: Run node tests
run: yarn workspace @noir-lang/noir_wasm test:node

Expand Down
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"tooling/backend_interface",
"tooling/bb_abstraction_leaks",
"tooling/lsp",
"tooling/lsp_wasm",
"tooling/nargo",
"tooling/nargo_cli",
"tooling/nargo_toml",
Expand All @@ -30,7 +31,7 @@ version = "0.12.0"
# x-release-please-end
authors = ["The Noir Team <[email protected]>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.67"
license = "MIT OR Apache-2.0"

[workspace.dependencies]
Expand All @@ -43,6 +44,7 @@ nargo = { path = "tooling/nargo" }
nargo_cli = { path = "tooling/nargo_cli" }
nargo_toml = { path = "tooling/nargo_toml" }
noir_lsp = { path = "tooling/lsp" }
noir_lsp_wasm = { path = "tooling/lsp_wasm" }
noirc_abi = { path = "tooling/noirc_abi" }
bb_abstraction_leaks = { path = "tooling/bb_abstraction_leaks" }
noirc_driver = { path = "compiler/noirc_driver" }
Expand Down Expand Up @@ -73,3 +75,5 @@ wasm-bindgen = { version = "=0.2.86", features = ["serde-serialize"] }
wasm-bindgen-test = "0.3.33"
base64 = "0.21.2"
fxhash = "0.2.1"
futures = { version = "0.3.28", default-features = false, features = ["async-await", "std", "executor"] }
rustix = { version = "0.38", default-features = false, features = [ "std", "fs" ] }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Concretely the following items are on the road map:

## Minimum Rust version

This crate's minimum supported rustc version is 1.66.0.
This crate's minimum supported rustc version is 1.67.0.

## Working on this project

Expand Down
22 changes: 20 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

rustToolchain = fenix.packages.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-Zk2rxv6vwKFkTTidgjPm6gDsseVmmljVt201H7zuDkk=";
sha256 = "sha256-riZUc+R9V35c/9e8KJUE+8pzpXyl0lRXt3ZkKlxoY0g=";
};

craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
Expand Down Expand Up @@ -125,6 +125,9 @@
noirc-abi-wasm-cargo-artifacts = craneLib.buildDepsOnly (wasmConfig // {
pname = "noirc_abi_wasm";
});
noir-lsp-wasm-cargo-artifacts = craneLib.buildDepsOnly (wasmConfig // {
pname = "noir_lsp_wasm";
});

nargo = craneLib.buildPackage (nativeConfig // {
pname = "nargo";
Expand Down Expand Up @@ -179,6 +182,19 @@
doCheck = false;
});

noir_lsp_wasm = craneLib.buildPackage (wasmConfig // rec {
pname = "noir_lsp_wasm";

inherit GIT_COMMIT GIT_DIRTY;

cargoArtifacts = noir-lsp-wasm-cargo-artifacts;

cargoExtraArgs = "--package ${pname} --target wasm32-wasi";

# We don't want to run tests because they don't work in the Nix sandbox
doCheck = false;
});

wasm-bindgen-cli = pkgs.callPackage ./wasm-bindgen-cli.nix {
rustPlatform = pkgs.makeRustPlatform {
rustc = rustToolchain;
Expand Down Expand Up @@ -211,17 +227,19 @@

# Nix flakes cannot build more than one derivation in one command (see https://github.com/NixOS/nix/issues/5591)
# so we use `symlinkJoin` to build everything as the "all" package.
all = pkgs.symlinkJoin { name = "all"; paths = [ nargo noir_wasm noirc_abi_wasm ]; };
all = pkgs.symlinkJoin { name = "all"; paths = [ nargo noir_wasm noirc_abi_wasm noir_lsp_wasm ]; };

# We also export individual packages to enable `nix build .#nargo -L`, etc.
inherit nargo;
inherit noir_wasm;
inherit noirc_abi_wasm;
inherit noir_lsp_wasm;

# We expose the `*-cargo-artifacts` derivations so we can cache our cargo dependencies in CI
inherit native-cargo-artifacts;
inherit noir-wasm-cargo-artifacts;
inherit noirc-abi-wasm-cargo-artifacts;
inherit noir-lsp-wasm-cargo-artifacts;
};

# Setup the environment to match the environment settings, the inputs from our checks derivations,
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.66.1"
channel = "1.67.0"
components = [ "rust-src" ]
targets = [ "wasm32-unknown-unknown", "wasm32-wasi", "aarch64-apple-darwin" ]
profile = "default"
2 changes: 1 addition & 1 deletion tooling/backend_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "The definition of the backend CLI interface which Nargo uses for
version = "0.11.0"
authors.workspace = true
edition.workspace = true
rust-version = "1.66"
rust-version = "1.67"
license.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
17 changes: 14 additions & 3 deletions tooling/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn on_initialize(
state: &mut LspState,
params: InitializeParams,
) -> impl Future<Output = Result<InitializeResult, ResponseError>> {
state.root_path = params.root_uri.and_then(|root_uri| root_uri.to_file_path().ok());
state.root_path = params.root_uri.and_then(|root_uri| uri_to_file_path(&root_uri).ok());

async {
let text_document_sync =
Expand Down Expand Up @@ -355,7 +355,7 @@ fn on_code_lens_request(
state: &mut LspState,
params: CodeLensParams,
) -> impl Future<Output = Result<CodeLensResult, ResponseError>> {
let file_path = match params.text_document.uri.to_file_path() {
let file_path = match uri_to_file_path(&params.text_document.uri) {
Ok(file_path) => file_path,
Err(()) => {
return future::ready(Err(ResponseError::new(
Expand Down Expand Up @@ -571,7 +571,7 @@ fn on_did_save_text_document(
state: &mut LspState,
params: DidSaveTextDocumentParams,
) -> ControlFlow<Result<(), async_lsp::Error>> {
let file_path = match params.text_document.uri.to_file_path() {
let file_path = match uri_to_file_path(&params.text_document.uri) {
Ok(file_path) => file_path,
Err(()) => {
return ControlFlow::Break(Err(ResponseError::new(
Expand Down Expand Up @@ -709,6 +709,8 @@ fn get_package_tests_in_crate(
package_tests.push(NargoTest {
id: NargoTestId::new(crate_name.clone(), func_name.clone()),
label: func_name,
// These `file://` URIs are currently normalized inside of the vscode extension
// TODO: Do proper normalization inside the LSP instead of at the extension
uri: Url::from_file_path(file_path)
.expect("Expected a valid file path that can be converted into a URI"),
range,
Expand Down Expand Up @@ -746,6 +748,15 @@ fn byte_span_to_range<'a, F: files::Files<'a> + ?Sized>(
}
}

// This smooths over `vscode-test-web://` or other schemes that may be sent from a browser client
fn uri_to_file_path(uri: &Url) -> Result<PathBuf, ()> {
if uri.scheme() == "vscode-test-web" {
Ok(PathBuf::from("/").join(uri.path()))
} else {
uri.to_file_path()
}
}

#[cfg(test)]
mod lsp_tests {
use lsp_types::TextDocumentSyncCapability;
Expand Down
17 changes: 17 additions & 0 deletions tooling/lsp_wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "noir_lsp_wasm"
description = "Language server for Noir compiled to WASI"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
acvm.workspace = true
noir_lsp.workspace = true
tower.workspace = true
futures.workspace = true
rustix.workspace = true
async-lsp = { version = "0.0.5", default-features = false, features = ["omni-trait"] }
35 changes: 35 additions & 0 deletions tooling/lsp_wasm/src/backend.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use acvm::BlackBoxFunctionSolver;

pub struct MockBackend;

impl BlackBoxFunctionSolver for MockBackend {
fn schnorr_verify(
&self,
_public_key_x: &acvm::FieldElement,
_public_key_y: &acvm::FieldElement,
_signature: &[u8],
_message: &[u8],
) -> Result<bool, acvm::BlackBoxResolutionError> {
unimplemented!(
"schnorr_verify blackbox function is not currently supported in the Wasm LSP"
)
}

fn pedersen(
&self,
_inputs: &[acvm::FieldElement],
_domain_separator: u32,
) -> Result<(acvm::FieldElement, acvm::FieldElement), acvm::BlackBoxResolutionError> {
unimplemented!("pedersen blackbox function is not currently supported in the Wasm LSP")
}

fn fixed_base_scalar_mul(
&self,
_low: &acvm::FieldElement,
_high: &acvm::FieldElement,
) -> Result<(acvm::FieldElement, acvm::FieldElement), acvm::BlackBoxResolutionError> {
unimplemented!(
"fixed_base_scalar_mul blackbox function is not currently supported in the Wasm LSP"
)
}
}
27 changes: 27 additions & 0 deletions tooling/lsp_wasm/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use async_lsp::{concurrency::ConcurrencyLayer, panic::CatchUnwindLayer, server::LifecycleLayer};
use noir_lsp::NargoLspService;
use tower::ServiceBuilder;

mod backend;
mod stdio;

fn main() {
// let blackbox_solver = acvm::blackbox_solver::BarretenbergSolver::initialize().await;
let blackbox_solver = backend::MockBackend;
let (server, _) = async_lsp::MainLoop::new_server(|client| {
let router = NargoLspService::new(&client, blackbox_solver);

ServiceBuilder::new()
.layer(LifecycleLayer::default())
.layer(CatchUnwindLayer::default())
.layer(ConcurrencyLayer::default())
.service(router)
});

let stdin = stdio::PipeStdin::lock().expect("stdin to lock");
let stdout = stdio::PipeStdout::lock().expect("stdout to lock");

futures::executor::block_on(async {
server.run_buffered(stdin, stdout).await.expect("server should start");
})
}
Loading