Skip to content

Commit

Permalink
LS: Proc macro server failed notification
Browse files Browse the repository at this point in the history
commit-id:d35d8322
  • Loading branch information
Draggu committed Nov 19, 2024
1 parent 27d8469 commit 08e4595
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ use super::client::{ProcMacroClient, RequestParams};
use crate::lang::db::AnalysisDatabase;
use crate::lang::proc_macros::db::ProcMacroGroup;
use crate::lang::proc_macros::plugins::proc_macro_plugin_suite;
use crate::lsp::ext::ProcMacroServerInitializationFailed;
use crate::server::client::Notifier;
use crate::toolchain::scarb::ScarbToolchain;

/// Manages lifecycle of proc-macro-server client.
pub struct ProcMacroClientController {
notifier: Notifier,
scarb: ScarbToolchain,
plugin_suite: Option<PluginSuite>,
initialization_retries: RateLimiter<NotKeyed, InMemoryState, QuantaClock>,
Expand All @@ -39,8 +42,9 @@ impl ProcMacroClientController {
(error_receiver, response_receiver)
}

pub fn new(scarb: ScarbToolchain) -> Self {
pub fn new(notifier: Notifier, scarb: ScarbToolchain) -> Self {
Self {
notifier,
scarb,
plugin_suite: Default::default(),
initialization_retries: RateLimiter::direct(
Expand Down Expand Up @@ -104,7 +108,7 @@ impl ProcMacroClientController {
fn fatal_failed(&self, db: &mut AnalysisDatabase) {
db.set_proc_macro_client_status(ClientStatus::FailedToInitialize);

// TODO Send notification.
self.notifier.notify::<ProcMacroServerInitializationFailed>(());
}

pub fn handle_error(&mut self, db: &mut AnalysisDatabase) {
Expand Down
9 changes: 9 additions & 0 deletions crates/cairo-lang-language-server/src/lsp/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ impl Notification for ScarbMetadataFailed {
type Params = ();
const METHOD: &'static str = "cairo/scarb-metadata-failed";
}

/// Notifies about `proc-macro-server` fatal fail.
#[derive(Debug)]
pub struct ProcMacroServerInitializationFailed;

impl Notification for ProcMacroServerInitializationFailed {
type Params = ();
const METHOD: &'static str = "cairo/procMacroServerInitializationFailed";
}
3 changes: 2 additions & 1 deletion crates/cairo-lang-language-server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ impl State {
let notifier = Client::new(sender).notifier();
let scarb_toolchain = ScarbToolchain::new(notifier.clone());
let db_swapper = AnalysisDatabaseSwapper::new(scarb_toolchain.clone());
let proc_macro_controller = ProcMacroClientController::new(scarb_toolchain.clone());
let proc_macro_controller =
ProcMacroClientController::new(notifier.clone(), scarb_toolchain.clone());

Self {
db: AnalysisDatabase::new(&tricks),
Expand Down

0 comments on commit 08e4595

Please sign in to comment.