From d55b2f68632bb59d6e72f804cf53797c429c2103 Mon Sep 17 00:00:00 2001 From: Piotr Magiera Date: Fri, 29 Nov 2024 06:03:43 +0100 Subject: [PATCH] Notify about invalid project config --- src/lsp/ext.rs | 15 +++++++++++++++ src/project/mod.rs | 27 +++++++++++++++++++++------ src/state.rs | 4 ++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/lsp/ext.rs b/src/lsp/ext.rs index aff7c7f..e8141b9 100644 --- a/src/lsp/ext.rs +++ b/src/lsp/ext.rs @@ -75,3 +75,18 @@ impl Notification for ProcMacroServerInitializationFailed { type Params = ProcMacroServerInitializationFailedParams; const METHOD: &'static str = "cairo/procMacroServerInitializationFailed"; } + +/// Notifies about `cairo_project.toml` parsing failure. +#[derive(Debug)] +pub struct ProjectConfigParsingFailed; + +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ProjectConfigParsingFailedParams { + pub project_config_path: String, +} + +impl Notification for ProjectConfigParsingFailed { + type Params = ProjectConfigParsingFailedParams; + const METHOD: &'static str = "cairo/projectConfigParsingFailed"; +} diff --git a/src/project/mod.rs b/src/project/mod.rs index fe63e2f..cc35206 100644 --- a/src/project/mod.rs +++ b/src/project/mod.rs @@ -10,7 +10,9 @@ use tracing::{debug, error, trace, warn}; pub use self::crate_data::Crate; pub use self::project_manifest_path::*; -use crate::lsp::ext::CorelibVersionMismatch; +use crate::lsp::ext::{ + CorelibVersionMismatch, ProjectConfigParsingFailed, ProjectConfigParsingFailedParams, +}; use crate::project::scarb::{extract_crates, get_workspace_members_manifests}; use crate::project::unmanaged_core_crate::try_to_init_unmanaged_core; use crate::server::client::Notifier; @@ -41,12 +43,16 @@ impl ProjectController { /// /// The background thread is responsible for fetching changes to the project model: check /// [`ProjectControllerThread::send_project_update_for_file`] for more information. - pub fn initialize(scarb_toolchain: ScarbToolchain) -> Self { + pub fn initialize(scarb_toolchain: ScarbToolchain, notifier: Notifier) -> Self { let (requests_sender, requests_receiver) = crossbeam::channel::unbounded(); let (response_sender, response_receiver) = crossbeam::channel::unbounded(); - let thread = - ProjectControllerThread::spawn(requests_receiver, response_sender, scarb_toolchain); + let thread = ProjectControllerThread::spawn( + requests_receiver, + response_sender, + scarb_toolchain, + notifier, + ); ProjectController { requests_sender, response_receiver, _thread: thread } } @@ -129,6 +135,7 @@ struct ProjectControllerThread { requests_receiver: Receiver, response_sender: Sender, scarb_toolchain: ScarbToolchain, + notifier: Notifier, } impl ProjectControllerThread { @@ -137,12 +144,14 @@ impl ProjectControllerThread { requests_receiver: Receiver, response_sender: Sender, scarb_toolchain: ScarbToolchain, + notifier: Notifier, ) -> JoinHandle { let this = Self { loaded_scarb_manifests: Default::default(), requests_receiver, response_sender, scarb_toolchain, + notifier, }; thread::Builder::new(ThreadPriority::Worker) @@ -208,8 +217,14 @@ impl ProjectControllerThread { assert!(config_path.is_absolute()); let maybe_project_config = ProjectConfig::from_file(&config_path) - // TODO: send failure notification - .inspect_err(|err| error!("{err:?}")) + .inspect_err(|err| { + error!("{err:?}"); + self.notifier.notify::( + ProjectConfigParsingFailedParams { + project_config_path: config_path.to_string_lossy().into(), + }, + ); + }) .ok(); ProjectUpdate::CairoProjectToml(maybe_project_config) } diff --git a/src/state.rs b/src/state.rs index bae723c..72e7525 100644 --- a/src/state.rs +++ b/src/state.rs @@ -48,9 +48,9 @@ impl State { scarb_toolchain: scarb_toolchain.clone(), db_swapper: AnalysisDatabaseSwapper::new(), tricks: Owned::new(tricks.into()), - diagnostics_controller: DiagnosticsController::new(notifier), + diagnostics_controller: DiagnosticsController::new(notifier.clone()), proc_macro_controller, - project_controller: ProjectController::initialize(scarb_toolchain), + project_controller: ProjectController::initialize(scarb_toolchain, notifier), } }