From b4a31867b606cb2622303ae7cb0cda82dc113914 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Mon, 5 Jun 2023 13:05:39 -0700 Subject: [PATCH 1/7] feat(nargo): Add lsp command to start server that reports no capabilities --- Cargo.lock | 127 +++++++++++++++++++++++ Cargo.toml | 4 + crates/nargo_cli/Cargo.toml | 19 +++- crates/nargo_cli/src/cli/lsp_cmd.rs | 48 +++++++++ crates/nargo_cli/src/cli/mod.rs | 5 +- crates/nargo_cli/src/errors.rs | 3 + crates/nargo_lsp/Cargo.toml | 17 ++++ crates/nargo_lsp/src/lib.rs | 150 ++++++++++++++++++++++++++++ 8 files changed, 369 insertions(+), 4 deletions(-) create mode 100644 crates/nargo_cli/src/cli/lsp_cmd.rs create mode 100644 crates/nargo_lsp/Cargo.toml create mode 100644 crates/nargo_lsp/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 9202e33a78f..1950d4430ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,6 +351,27 @@ dependencies = [ "tempfile", ] +[[package]] +name = "async-lsp" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73395fba7765010f2a98d007d601bd47e0d31ada90cd82f40c7eab753eba0870" +dependencies = [ + "either", + "futures", + "libc", + "lsp-types", + "pin-project-lite", + "rustix", + "serde", + "serde_json", + "thiserror", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "async-trait" version = "0.1.68" @@ -1226,6 +1247,20 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.28" @@ -1233,6 +1268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -1241,6 +1277,23 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-macro" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + [[package]] name = "futures-sink" version = "0.3.28" @@ -1259,10 +1312,16 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -1758,6 +1817,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "lsp-types" +version = "0.94.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b63735a13a1f9cd4f4835223d828ed9c2e35c8c5e61837774399f558b6a1237" +dependencies = [ + "bitflags", + "serde", + "serde_json", + "serde_repr", + "url", +] + [[package]] name = "mach" version = "0.3.2" @@ -1868,6 +1940,7 @@ dependencies = [ "acvm-backend-barretenberg", "assert_cmd", "assert_fs", + "async-lsp", "build-data", "cfg-if", "clap", @@ -1877,6 +1950,7 @@ dependencies = [ "hex", "iter-extended", "nargo", + "nargo_lsp", "noirc_abi", "noirc_driver", "noirc_frontend", @@ -1889,9 +1963,21 @@ dependencies = [ "thiserror", "tokio", "toml", + "tower", "url", ] +[[package]] +name = "nargo_lsp" +version = "0.6.0" +dependencies = [ + "async-lsp", + "lsp-types", + "serde_json", + "tokio", + "tower", +] + [[package]] name = "noir_wasm" version = "0.6.0" @@ -2800,6 +2886,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_repr" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + [[package]] name = "serde_spanned" version = "0.6.2" @@ -3134,9 +3231,21 @@ dependencies = [ "mio", "pin-project-lite", "socket2", + "tokio-macros", "windows-sys 0.48.0", ] +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + [[package]] name = "tokio-rustls" version = "0.24.0" @@ -3195,6 +3304,23 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -3316,6 +3442,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b56e140ed58..f52753a8085 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ fm = { path = "crates/fm" } iter-extended = { path = "crates/iter-extended" } nargo = { path = "crates/nargo" } nargo_cli = { path = "crates/nargo_cli" } +nargo_lsp = { path = "crates/nargo_lsp" } noirc_abi = { path = "crates/noirc_abi" } noirc_driver = { path = "crates/noirc_driver" } noirc_errors = { path = "crates/noirc_errors" } @@ -37,6 +38,7 @@ noirc_evaluator = { path = "crates/noirc_evaluator" } noirc_frontend = { path = "crates/noirc_frontend" } noir_wasm = { path = "crates/wasm" } +async-lsp = { version = "0.0.4", default-features = false, features = ["omni-trait"] } cfg-if = "1.0.0" clap = { version = "4.1.4", features = ["derive"]} codespan = "0.9.5" @@ -44,9 +46,11 @@ codespan-reporting = "0.9.5" chumsky = { git = "https://github.com/jfecher/chumsky", rev = "ad9d312" } dirs = "4" serde = { version = "1.0.136", features = ["derive"] } +serde_json = "1.0" smol_str = "0.1.17" thiserror = "1.0.21" toml = "0.7.2" +tower = "0.4" url = "2.2.0" wasm-bindgen = { version = "0.2.83", features = ["serde-serialize"] } wasm-bindgen-test = "0.3.33" diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index 4d4cdc75159..966f3a33909 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -18,22 +18,25 @@ build-data = "0.1.3" toml.workspace = true [dependencies] +async-lsp.workspace = true cfg-if.workspace = true clap.workspace = true dirs.workspace = true url.workspace = true iter-extended.workspace = true nargo.workspace = true +nargo_lsp.workspace = true noirc_driver.workspace = true noirc_frontend.workspace = true noirc_abi.workspace = true acvm.workspace = true toml.workspace = true serde.workspace = true +serde_json.workspace = true thiserror.workspace = true +tower.workspace = true const_format = "0.2.30" hex = "0.4.2" -serde_json = "1.0" termcolor = "1.1.2" color-eyre = "0.6.2" tokio = "1.0" @@ -50,5 +53,15 @@ predicates = "2.1.5" [features] default = ["plonk_bn254"] # The plonk backend can only use bn254, so we do not specify the field -plonk_bn254 = ["acvm-backend-barretenberg/native"] -plonk_bn254_wasm = ["acvm-backend-barretenberg/wasm"] +plonk_bn254 = [ + "acvm-backend-barretenberg/native", + "async-lsp/client-monitor", + "async-lsp/stdio", + "async-lsp/tracing" +] +plonk_bn254_wasm = [ + "acvm-backend-barretenberg/wasm", + "async-lsp/client-monitor", + "async-lsp/stdio", + "async-lsp/tracing" +] diff --git a/crates/nargo_cli/src/cli/lsp_cmd.rs b/crates/nargo_cli/src/cli/lsp_cmd.rs new file mode 100644 index 00000000000..aab3be9d33e --- /dev/null +++ b/crates/nargo_cli/src/cli/lsp_cmd.rs @@ -0,0 +1,48 @@ +use acvm::Backend; +use async_lsp::{ + client_monitor::ClientProcessMonitorLayer, concurrency::ConcurrencyLayer, + panic::CatchUnwindLayer, server::LifecycleLayer, stdio::PipeStdin, tracing::TracingLayer, +}; +use clap::Args; +use nargo_lsp::NargoLspService; +use noirc_driver::CompileOptions; +use tokio::io::BufReader; +use tower::ServiceBuilder; + +use super::NargoConfig; +use crate::errors::CliError; + +#[derive(Debug, Clone, Args)] +pub(crate) struct LspCommand { + #[clap(flatten)] + compile_options: CompileOptions, +} + +pub(crate) fn run( + // Backend is currently unused, but we might want to use it to inform the lsp in the future + _backend: &B, + _args: LspCommand, + _config: NargoConfig, +) -> Result<(), CliError> { + use tokio::runtime::Builder; + + let runtime = Builder::new_current_thread().enable_all().build().unwrap(); + + let (server, _) = async_lsp::Frontend::new_server(|client| { + let router = NargoLspService::new(); + + ServiceBuilder::new() + .layer(TracingLayer::default()) + .layer(LifecycleLayer::default()) + .layer(CatchUnwindLayer::default()) + .layer(ConcurrencyLayer::default()) + .layer(ClientProcessMonitorLayer::new(client)) + .service(router) + }); + + runtime.block_on(async { + let stdin = BufReader::new(PipeStdin::lock().unwrap()); + let stdout = async_lsp::stdio::PipeStdout::lock().unwrap(); + server.run(stdin, stdout).await.map_err(CliError::LspError) + }) +} diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index 9c1c7b7c2cc..bf188f3ac81 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -14,6 +14,7 @@ mod codegen_verifier_cmd; mod compile_cmd; mod execute_cmd; mod gates_cmd; +mod lsp_cmd; mod new_cmd; mod prove_cmd; mod test_cmd; @@ -55,13 +56,14 @@ enum NargoCommand { Verify(verify_cmd::VerifyCommand), Test(test_cmd::TestCommand), Gates(gates_cmd::GatesCommand), + Lsp(lsp_cmd::LspCommand), } pub fn start_cli() -> eyre::Result<()> { let NargoCli { command, mut config } = NargoCli::parse(); // Search through parent directories to find package root if necessary. - if !matches!(command, NargoCommand::New(_)) { + if !matches!(command, NargoCommand::New(_)) && !matches!(command, NargoCommand::Lsp(_)) { config.program_dir = find_package_root(&config.program_dir)?; } @@ -77,6 +79,7 @@ pub fn start_cli() -> eyre::Result<()> { NargoCommand::Test(args) => test_cmd::run(&backend, args, config), NargoCommand::Gates(args) => gates_cmd::run(&backend, args, config), NargoCommand::CodegenVerifier(args) => codegen_verifier_cmd::run(&backend, args, config), + NargoCommand::Lsp(args) => lsp_cmd::run(&backend, args, config), }?; Ok(()) diff --git a/crates/nargo_cli/src/errors.rs b/crates/nargo_cli/src/errors.rs index 02bc5b031a9..c3e295183d1 100644 --- a/crates/nargo_cli/src/errors.rs +++ b/crates/nargo_cli/src/errors.rs @@ -55,6 +55,9 @@ pub(crate) enum CliError { #[error(transparent)] FilesystemError(#[from] FilesystemError), + #[error(transparent)] + LspError(#[from] async_lsp::Error), + /// Error from Nargo #[error(transparent)] NargoError(#[from] NargoError), diff --git a/crates/nargo_lsp/Cargo.toml b/crates/nargo_lsp/Cargo.toml new file mode 100644 index 00000000000..2ba135a9eb6 --- /dev/null +++ b/crates/nargo_lsp/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "nargo_lsp" +description = "Language server for Noir" +version.workspace = true +authors.workspace = true +edition.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +async-lsp.workspace = true +serde_json.workspace = true +tower.workspace = true +lsp-types = "0.94" + +[dev-dependencies] +tokio = { version = "1.0", features = ["macros"] } diff --git a/crates/nargo_lsp/src/lib.rs b/crates/nargo_lsp/src/lib.rs new file mode 100644 index 00000000000..2a31f547189 --- /dev/null +++ b/crates/nargo_lsp/src/lib.rs @@ -0,0 +1,150 @@ +use std::{ + future::Future, + ops::ControlFlow, + pin::Pin, + task::{Context, Poll}, +}; + +use async_lsp::{ + router::Router, AnyEvent, AnyNotification, AnyRequest, Error, LspService, ResponseError, +}; +use lsp_types::{ + notification, request, DidChangeConfigurationParams, DidChangeTextDocumentParams, + DidCloseTextDocumentParams, DidOpenTextDocumentParams, InitializeParams, InitializeResult, + InitializedParams, ServerCapabilities, +}; +use serde_json::Value as JsonValue; +use tower::Service; + +// State for the LSP gets implemented on this struct and is internal to the implementation +#[derive(Debug, Default)] +struct LspState; + +pub struct NargoLspService { + router: Router, +} + +impl NargoLspService { + pub fn new() -> Self { + let state = LspState::default(); + let mut router = Router::new(state); + router + .request::(on_initialize) + .notification::(on_initialized) + .notification::(on_did_change_configuration) + .notification::(on_did_open_text_document) + .notification::(on_did_change_text_document) + .notification::(on_did_close_text_document); + Self { router } + } +} + +impl Default for NargoLspService { + fn default() -> Self { + Self::new() + } +} + +// This trait implemented as a passthrough to the router, which makes +// our `NargoLspService` a normal Service as far as Tower is concerned. +impl Service for NargoLspService { + type Response = JsonValue; + type Error = ResponseError; + type Future = Pin> + Send>>; + + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + self.router.poll_ready(cx) + } + + fn call(&mut self, req: AnyRequest) -> Self::Future { + self.router.call(req) + } +} + +// This trait implemented as a passthrough to the router, which makes +// our `NargoLspService` able to accept the `async-lsp` middleware. +impl LspService for NargoLspService { + fn notify(&mut self, notif: AnyNotification) -> ControlFlow> { + self.router.notify(notif) + } + + fn emit(&mut self, event: AnyEvent) -> ControlFlow> { + self.router.emit(event) + } +} + +// Handlers +// The handlers for `request` are not `async` because it compiles down to lifetimes that can't be added to +// the router. To return a future that fits the trait, it is easiest wrap your implementations in an `async {}` +// block but you can also use `std::future::ready`. +// +// Additionally, the handlers for `notification` aren't async at all. +// +// They are not attached to the `NargoLspService` struct so they can be unit tested with only `LspState` +// and params passed in. + +fn on_initialize( + _state: &mut LspState, + _params: InitializeParams, +) -> impl Future> { + async { + Ok(InitializeResult { + capabilities: ServerCapabilities { + // Add capabilities before this spread when adding support for one + ..ServerCapabilities::default() + }, + server_info: None, + }) + } +} + +fn on_initialized( + _state: &mut LspState, + _params: InitializedParams, +) -> ControlFlow> { + ControlFlow::Continue(()) +} + +fn on_did_change_configuration( + _state: &mut LspState, + _params: DidChangeConfigurationParams, +) -> ControlFlow> { + ControlFlow::Continue(()) +} + +fn on_did_open_text_document( + _state: &mut LspState, + _params: DidOpenTextDocumentParams, +) -> ControlFlow> { + ControlFlow::Continue(()) +} + +fn on_did_change_text_document( + _state: &mut LspState, + _params: DidChangeTextDocumentParams, +) -> ControlFlow> { + ControlFlow::Continue(()) +} + +fn on_did_close_text_document( + _state: &mut LspState, + _params: DidCloseTextDocumentParams, +) -> ControlFlow> { + ControlFlow::Continue(()) +} + +#[cfg(test)] +mod lsp_tests { + use tokio::test; + + use super::*; + + #[test] + async fn test_on_initialize() { + let mut state = LspState::default(); + let params = InitializeParams::default(); + let response = on_initialize(&mut state, params).await.unwrap(); + assert_eq!(response.capabilities, ServerCapabilities::default()); + assert!(response.server_info.is_none()); + } +} From 2b9249ff8e0d3ba80a9f98d0b98389ffb393523d Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 6 Jun 2023 08:31:36 -0700 Subject: [PATCH 2/7] move async-lsp dep into crates to use different features --- Cargo.toml | 1 - crates/nargo_cli/Cargo.toml | 16 +++------------- crates/nargo_lsp/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f52753a8085..2b3e9990764 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,6 @@ noirc_evaluator = { path = "crates/noirc_evaluator" } noirc_frontend = { path = "crates/noirc_frontend" } noir_wasm = { path = "crates/wasm" } -async-lsp = { version = "0.0.4", default-features = false, features = ["omni-trait"] } cfg-if = "1.0.0" clap = { version = "4.1.4", features = ["derive"]} codespan = "0.9.5" diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index 966f3a33909..c139ed911f0 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -18,7 +18,6 @@ build-data = "0.1.3" toml.workspace = true [dependencies] -async-lsp.workspace = true cfg-if.workspace = true clap.workspace = true dirs.workspace = true @@ -35,6 +34,7 @@ serde.workspace = true serde_json.workspace = true thiserror.workspace = true tower.workspace = true +async-lsp = { version = "0.0.4", default-features = false, features = ["client-monitor", "stdio", "tracing"] } const_format = "0.2.30" hex = "0.4.2" termcolor = "1.1.2" @@ -53,15 +53,5 @@ predicates = "2.1.5" [features] default = ["plonk_bn254"] # The plonk backend can only use bn254, so we do not specify the field -plonk_bn254 = [ - "acvm-backend-barretenberg/native", - "async-lsp/client-monitor", - "async-lsp/stdio", - "async-lsp/tracing" -] -plonk_bn254_wasm = [ - "acvm-backend-barretenberg/wasm", - "async-lsp/client-monitor", - "async-lsp/stdio", - "async-lsp/tracing" -] +plonk_bn254 = ["acvm-backend-barretenberg/native"] +plonk_bn254_wasm = ["acvm-backend-barretenberg/wasm"] diff --git a/crates/nargo_lsp/Cargo.toml b/crates/nargo_lsp/Cargo.toml index 2ba135a9eb6..758b64bc352 100644 --- a/crates/nargo_lsp/Cargo.toml +++ b/crates/nargo_lsp/Cargo.toml @@ -8,9 +8,9 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -async-lsp.workspace = true serde_json.workspace = true tower.workspace = true +async-lsp = { version = "0.0.4", default-features = false, features = ["omni-trait"] } lsp-types = "0.94" [dev-dependencies] From 9b57aa7da614f8143cdff9ef288552f567929e10 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 6 Jun 2023 08:32:43 -0700 Subject: [PATCH 3/7] cspell --- crates/nargo_lsp/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/nargo_lsp/src/lib.rs b/crates/nargo_lsp/src/lib.rs index 2a31f547189..b25faddc7be 100644 --- a/crates/nargo_lsp/src/lib.rs +++ b/crates/nargo_lsp/src/lib.rs @@ -64,8 +64,8 @@ impl Service for NargoLspService { // This trait implemented as a passthrough to the router, which makes // our `NargoLspService` able to accept the `async-lsp` middleware. impl LspService for NargoLspService { - fn notify(&mut self, notif: AnyNotification) -> ControlFlow> { - self.router.notify(notif) + fn notify(&mut self, notification: AnyNotification) -> ControlFlow> { + self.router.notify(notification) } fn emit(&mut self, event: AnyEvent) -> ControlFlow> { From c8531a91233d1518b84b0b6b1c2057b06fdb30e5 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 6 Jun 2023 10:30:55 -0700 Subject: [PATCH 4/7] utilize pattern in matches --- crates/nargo_cli/src/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index bf188f3ac81..861e322fd9e 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -63,7 +63,7 @@ pub fn start_cli() -> eyre::Result<()> { let NargoCli { command, mut config } = NargoCli::parse(); // Search through parent directories to find package root if necessary. - if !matches!(command, NargoCommand::New(_)) && !matches!(command, NargoCommand::Lsp(_)) { + if !matches!(command, NargoCommand::New(_) | NargoCommand::Lsp(_)) { config.program_dir = find_package_root(&config.program_dir)?; } From 0931cc28238306231452424946131e067308ecc9 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 6 Jun 2023 10:40:09 -0700 Subject: [PATCH 5/7] handle shutdown and exit to make vscode plugin happy --- crates/nargo_lsp/src/lib.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/nargo_lsp/src/lib.rs b/crates/nargo_lsp/src/lib.rs index b25faddc7be..3b5b8daa9a9 100644 --- a/crates/nargo_lsp/src/lib.rs +++ b/crates/nargo_lsp/src/lib.rs @@ -30,11 +30,13 @@ impl NargoLspService { let mut router = Router::new(state); router .request::(on_initialize) + .request::(on_shutdown) .notification::(on_initialized) .notification::(on_did_change_configuration) .notification::(on_did_open_text_document) .notification::(on_did_change_text_document) - .notification::(on_did_close_text_document); + .notification::(on_did_close_text_document) + .notification::(on_exit); Self { router } } } @@ -98,6 +100,13 @@ fn on_initialize( } } +fn on_shutdown( + _state: &mut LspState, + _params: (), +) -> impl Future> { + async { Ok(()) } +} + fn on_initialized( _state: &mut LspState, _params: InitializedParams, @@ -133,6 +142,10 @@ fn on_did_close_text_document( ControlFlow::Continue(()) } +fn on_exit(_state: &mut LspState, _params: ()) -> ControlFlow> { + ControlFlow::Continue(()) +} + #[cfg(test)] mod lsp_tests { use tokio::test; From 7b864943fee5a519abee3965cea7e6b74d5f1f33 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 6 Jun 2023 10:42:24 -0700 Subject: [PATCH 6/7] rename nargo_lsp to noir_lsp & move dir --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/{nargo_lsp => lsp}/Cargo.toml | 2 +- crates/{nargo_lsp => lsp}/src/lib.rs | 0 crates/nargo_cli/Cargo.toml | 2 +- crates/nargo_cli/src/cli/lsp_cmd.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename crates/{nargo_lsp => lsp}/Cargo.toml (96%) rename crates/{nargo_lsp => lsp}/src/lib.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 1950d4430ef..966176e00c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1950,7 +1950,7 @@ dependencies = [ "hex", "iter-extended", "nargo", - "nargo_lsp", + "noir_lsp", "noirc_abi", "noirc_driver", "noirc_frontend", @@ -1968,7 +1968,7 @@ dependencies = [ ] [[package]] -name = "nargo_lsp" +name = "noir_lsp" version = "0.6.0" dependencies = [ "async-lsp", diff --git a/Cargo.toml b/Cargo.toml index 2b3e9990764..b485e87a1c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ fm = { path = "crates/fm" } iter-extended = { path = "crates/iter-extended" } nargo = { path = "crates/nargo" } nargo_cli = { path = "crates/nargo_cli" } -nargo_lsp = { path = "crates/nargo_lsp" } +noir_lsp = { path = "crates/lsp" } noirc_abi = { path = "crates/noirc_abi" } noirc_driver = { path = "crates/noirc_driver" } noirc_errors = { path = "crates/noirc_errors" } diff --git a/crates/nargo_lsp/Cargo.toml b/crates/lsp/Cargo.toml similarity index 96% rename from crates/nargo_lsp/Cargo.toml rename to crates/lsp/Cargo.toml index 758b64bc352..9c440e6b01a 100644 --- a/crates/nargo_lsp/Cargo.toml +++ b/crates/lsp/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "nargo_lsp" +name = "noir_lsp" description = "Language server for Noir" version.workspace = true authors.workspace = true diff --git a/crates/nargo_lsp/src/lib.rs b/crates/lsp/src/lib.rs similarity index 100% rename from crates/nargo_lsp/src/lib.rs rename to crates/lsp/src/lib.rs diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index c139ed911f0..840232a64c6 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -24,7 +24,7 @@ dirs.workspace = true url.workspace = true iter-extended.workspace = true nargo.workspace = true -nargo_lsp.workspace = true +noir_lsp.workspace = true noirc_driver.workspace = true noirc_frontend.workspace = true noirc_abi.workspace = true diff --git a/crates/nargo_cli/src/cli/lsp_cmd.rs b/crates/nargo_cli/src/cli/lsp_cmd.rs index aab3be9d33e..189cf7992b5 100644 --- a/crates/nargo_cli/src/cli/lsp_cmd.rs +++ b/crates/nargo_cli/src/cli/lsp_cmd.rs @@ -4,7 +4,7 @@ use async_lsp::{ panic::CatchUnwindLayer, server::LifecycleLayer, stdio::PipeStdin, tracing::TracingLayer, }; use clap::Args; -use nargo_lsp::NargoLspService; +use noir_lsp::NargoLspService; use noirc_driver::CompileOptions; use tokio::io::BufReader; use tower::ServiceBuilder; From f65f4ed82a4d42b99eae78973412fc33fe9037d4 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 6 Jun 2023 10:44:57 -0700 Subject: [PATCH 7/7] add lsp to the crates readme --- crates/readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/readme.md b/crates/readme.md index 6e1d6efc9f8..7f7c3b86988 100644 --- a/crates/readme.md +++ b/crates/readme.md @@ -14,6 +14,10 @@ This is the virtual machine that runs ACIR. Given a proving system to power it, This is the abstraction that the compiler uses to manage source files. +## lsp + +This is the platform agnostic implementation of Noir's Language Server. It implements the various features supported, but doesn't bind to any particular transport. Binding to a transport must be done when consuming the crate. + ## nargo This is the default package manager used by Noir. One may draw similarities to Rusts' Cargo.