Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notify about invalid project config
Browse files Browse the repository at this point in the history
piotmag769 committed Dec 2, 2024
1 parent 1c4d493 commit d55b2f6
Showing 3 changed files with 38 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/lsp/ext.rs
Original file line number Diff line number Diff line change
@@ -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";
}
27 changes: 21 additions & 6 deletions src/project/mod.rs
Original file line number Diff line number Diff line change
@@ -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<ProjectControllerRequest>,
response_sender: Sender<ProjectUpdate>,
scarb_toolchain: ScarbToolchain,
notifier: Notifier,
}

impl ProjectControllerThread {
@@ -137,12 +144,14 @@ impl ProjectControllerThread {
requests_receiver: Receiver<ProjectControllerRequest>,
response_sender: Sender<ProjectUpdate>,
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::<ProjectConfigParsingFailed>(
ProjectConfigParsingFailedParams {
project_config_path: config_path.to_string_lossy().into(),
},
);
})
.ok();
ProjectUpdate::CairoProjectToml(maybe_project_config)
}
4 changes: 2 additions & 2 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -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),
}
}

0 comments on commit d55b2f6

Please sign in to comment.