Skip to content

Commit

Permalink
Change client_status to server_status for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcticae committed Feb 11, 2025
1 parent 65cd18b commit ccad024
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/lang/db/swapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl AnalysisDatabaseSwapper {
new_db.set_inline_macro_plugins(old_db.inline_macro_plugins());
new_db.set_analyzer_plugins(old_db.analyzer_plugins());

new_db.set_proc_macro_client_status(old_db.proc_macro_client_status());
new_db.set_proc_macro_server_status(old_db.proc_macro_server_status());

// TODO(#6646): Probably this should not be part of migration as it will be ever growing,
// but diagnostics going crazy every 5 minutes are no better.
Expand Down
2 changes: 1 addition & 1 deletion src/lang/proc_macros/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use scarb_proc_macro_server_types::methods::expand::{
ExpandAttribute, ExpandAttributeParams, ExpandDerive, ExpandDeriveParams, ExpandInline,
ExpandInlineMacroParams,
};
pub use status::ClientStatus;
pub use status::ServerStatus;
use tracing::error;

use crate::ide::analysis_progress::ProcMacroServerTracker;
Expand Down
4 changes: 2 additions & 2 deletions src/lang/proc_macros/client/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use super::ProcMacroClient;

#[derive(Debug, Default, Clone)]
pub enum ClientStatus {
pub enum ServerStatus {
#[default]
Pending,
Starting(Arc<ProcMacroClient>),
Expand All @@ -13,7 +13,7 @@ pub enum ClientStatus {
Crashed,
}

impl ClientStatus {
impl ServerStatus {
pub fn ready(&self) -> Option<&ProcMacroClient> {
if let Self::Ready(client) = self { Some(client) } else { None }
}
Expand Down
36 changes: 18 additions & 18 deletions src/lang/proc_macros/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use scarb_proc_macro_server_types::methods::ProcMacroResult;
use tracing::error;

use super::client::connection::ProcMacroServerConnection;
use super::client::status::ClientStatus;
use super::client::status::ServerStatus;
use super::client::{ProcMacroClient, RequestParams};
use crate::config::Config;
use crate::ide::analysis_progress::{ProcMacroServerStatus, ProcMacroServerTracker};
Expand Down Expand Up @@ -57,13 +57,13 @@ pub struct ProcMacroClientController {
proc_macro_server_tracker: ProcMacroServerTracker,
}

impl From<&ClientStatus> for ProcMacroServerStatus {
fn from(value: &ClientStatus) -> Self {
impl From<&ServerStatus> for ProcMacroServerStatus {
fn from(value: &ServerStatus) -> Self {
match value {
ClientStatus::Pending => ProcMacroServerStatus::Pending,
ClientStatus::Starting(_) => ProcMacroServerStatus::Starting,
ClientStatus::Ready(_) => ProcMacroServerStatus::Ready,
ClientStatus::Crashed => ProcMacroServerStatus::Crashed,
ServerStatus::Pending => ProcMacroServerStatus::Pending,
ServerStatus::Starting(_) => ProcMacroServerStatus::Starting,
ServerStatus::Ready(_) => ProcMacroServerStatus::Ready,
ServerStatus::Crashed => ProcMacroServerStatus::Crashed,
}
}
}
Expand Down Expand Up @@ -102,15 +102,15 @@ impl ProcMacroClientController {
/// `ClientStatus::Starting` if config allows this.
#[tracing::instrument(level = "trace", skip_all)]
pub fn on_config_change(&mut self, db: &mut AnalysisDatabase, config: &Config) {
if db.proc_macro_client_status().is_pending() {
if db.proc_macro_server_status().is_pending() {
self.try_initialize(db, config);
}
}

fn set_proc_macro_client_status(&self, db: &mut AnalysisDatabase, client_status: ClientStatus) {
let server_status = ProcMacroServerStatus::from(&client_status);
db.set_proc_macro_client_status(client_status);
self.proc_macro_server_tracker.set_server_status(server_status);
fn set_proc_macro_server_status(&self, db: &mut AnalysisDatabase, server_status: ServerStatus) {
let tracker_server_status = ProcMacroServerStatus::from(&server_status);
db.set_proc_macro_server_status(server_status);
self.proc_macro_server_tracker.set_server_status(tracker_server_status);
}

/// Forcibly restarts the proc-macro-server, shutting down any currently running instances.
Expand Down Expand Up @@ -144,8 +144,8 @@ impl ProcMacroClientController {
/// If the client is ready, apply all available responses.
#[tracing::instrument(level = "trace", skip_all)]
pub fn on_response(&mut self, db: &mut AnalysisDatabase, config: &Config) {
match db.proc_macro_client_status() {
ClientStatus::Starting(client) => {
match db.proc_macro_server_status() {
ServerStatus::Starting(client) => {
let Ok(defined_macros) = client.finish_initialize() else {
self.handle_error(db, config);

Expand All @@ -164,9 +164,9 @@ impl ProcMacroClientController {
db.add_plugin_suite(new_plugin_suite);
}

self.set_proc_macro_client_status(db, ClientStatus::Ready(client));
self.set_proc_macro_server_status(db, ServerStatus::Ready(client));
}
ClientStatus::Ready(client) => {
ServerStatus::Ready(client) => {
self.apply_responses(db, config, &client);
}
_ => {}
Expand Down Expand Up @@ -205,7 +205,7 @@ impl ProcMacroClientController {

client.start_initialize();

self.set_proc_macro_client_status(db, ClientStatus::Starting(Arc::new(client)));
db.set_proc_macro_server_status(ServerStatus::Starting(Arc::new(client)));
}
Err(err) => {
error!("spawning proc-macro-server failed: {err:?}");
Expand All @@ -221,7 +221,7 @@ impl ProcMacroClientController {
db: &mut AnalysisDatabase,
initialization_failed_info: InitializationFailedInfo,
) {
self.set_proc_macro_client_status(db, ClientStatus::Crashed);
self.set_proc_macro_server_status(db, ServerStatus::Crashed);

self.notifier.notify::<ShowMessage>(ShowMessageParams {
typ: MessageType::ERROR,
Expand Down
12 changes: 6 additions & 6 deletions src/lang/proc_macros/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use scarb_proc_macro_server_types::methods::expand::{
ExpandAttributeParams, ExpandDeriveParams, ExpandInlineMacroParams,
};

use super::client::ClientStatus;
use super::client::ServerStatus;

/// A set of queries that enable access to proc macro client from compiler plugins
/// `.generate_code()` methods.
Expand All @@ -21,7 +21,7 @@ pub trait ProcMacroGroup {
fn inline_macro_resolution(&self) -> Arc<HashMap<ExpandInlineMacroParams, ProcMacroResult>>;

#[salsa::input]
fn proc_macro_client_status(&self) -> ClientStatus;
fn proc_macro_server_status(&self) -> ServerStatus;

/// Returns the expansion of attribute macro.
fn get_attribute_expansion(&self, params: ExpandAttributeParams) -> ProcMacroResult;
Expand All @@ -35,7 +35,7 @@ pub fn init_proc_macro_group(db: &mut dyn ProcMacroGroup) {
db.set_attribute_macro_resolution(Default::default());
db.set_derive_macro_resolution(Default::default());
db.set_inline_macro_resolution(Default::default());
db.set_proc_macro_client_status(Default::default());
db.set_proc_macro_server_status(Default::default());
}

fn get_attribute_expansion(
Expand All @@ -45,7 +45,7 @@ fn get_attribute_expansion(
db.attribute_macro_resolution().get(&params).cloned().unwrap_or_else(|| {
let token_stream = params.item.clone();

if let Some(client) = db.proc_macro_client_status().ready() {
if let Some(client) = db.proc_macro_server_status().ready() {
client.request_attribute(params);
}

Expand All @@ -57,7 +57,7 @@ fn get_derive_expansion(db: &dyn ProcMacroGroup, params: ExpandDeriveParams) ->
db.derive_macro_resolution().get(&params).cloned().unwrap_or_else(|| {
let token_stream = params.item.clone();

if let Some(client) = db.proc_macro_client_status().ready() {
if let Some(client) = db.proc_macro_server_status().ready() {
client.request_derives(params);
}

Expand All @@ -73,7 +73,7 @@ fn get_inline_macros_expansion(
// we can't return original node because it will make infinite recursive resolving.
let token_stream = TokenStream::new("()".to_string());

if let Some(client) = db.proc_macro_client_status().ready() {
if let Some(client) = db.proc_macro_server_status().ready() {
client.request_inline_macros(params);
}

Expand Down

0 comments on commit ccad024

Please sign in to comment.