@@ -15,6 +15,7 @@ use tracing::error;
1515use super :: client:: connection:: ProcMacroServerConnection ;
1616use super :: client:: status:: ClientStatus ;
1717use super :: client:: { ProcMacroClient , RequestParams } ;
18+ use crate :: config:: Config ;
1819use crate :: lang:: db:: AnalysisDatabase ;
1920use crate :: lang:: proc_macros:: db:: ProcMacroGroup ;
2021use crate :: lang:: proc_macros:: plugins:: proc_macro_plugin_suite;
@@ -84,18 +85,18 @@ impl ProcMacroClientController {
8485 }
8586 }
8687
87- /// Start proc-macro-server.
88+ /// Start proc-macro-server after config reload .
8889 /// Note that this will only try to go from `ClientStatus::Pending` to
89- /// `ClientStatus::Starting`.
90- pub fn initialize_once ( & mut self , db : & mut AnalysisDatabase ) {
90+ /// `ClientStatus::Starting` if config allows this .
91+ pub fn on_config_change ( & mut self , db : & mut AnalysisDatabase , config : & Config ) {
9192 if db. proc_macro_client_status ( ) . is_pending ( ) {
92- self . try_initialize ( db) ;
93+ self . try_initialize ( db, config ) ;
9394 }
9495 }
9596
9697 /// Check if an error was reported. If so, try to restart.
97- pub fn handle_error ( & mut self , db : & mut AnalysisDatabase ) {
98- if !self . try_initialize ( db) {
98+ pub fn handle_error ( & mut self , db : & mut AnalysisDatabase , config : & Config ) {
99+ if !self . try_initialize ( db, config ) {
99100 self . fatal_failed ( db, ProcMacroServerInitializationFailedParams :: NoMoreRetries {
100101 retries : RATE_LIMITER_RETRIES ,
101102 in_minutes : RATE_LIMITER_PERIOD_SEC / 60 ,
@@ -104,11 +105,11 @@ impl ProcMacroClientController {
104105 }
105106
106107 /// If the client is ready, apply all available responses.
107- pub fn on_response ( & mut self , db : & mut AnalysisDatabase ) {
108+ pub fn on_response ( & mut self , db : & mut AnalysisDatabase , config : & Config ) {
108109 match db. proc_macro_client_status ( ) {
109110 ClientStatus :: Starting ( client) => {
110111 let Ok ( defined_macros) = client. finish_initialize ( ) else {
111- self . handle_error ( db) ;
112+ self . handle_error ( db, config ) ;
112113
113114 return ;
114115 } ;
@@ -124,17 +125,19 @@ impl ProcMacroClientController {
124125 db. set_proc_macro_client_status ( ClientStatus :: Ready ( client) ) ;
125126 }
126127 ClientStatus :: Ready ( client) => {
127- self . apply_responses ( db, & client) ;
128+ self . apply_responses ( db, config , & client) ;
128129 }
129130 _ => { }
130131 }
131132 }
132133
133- /// Tries starting proc-macro-server initialization process.
134+ /// Tries starting proc-macro-server initialization process, if allowed by config .
134135 ///
135136 /// Returns value indicating if initialization was attempted.
136- fn try_initialize ( & mut self , db : & mut AnalysisDatabase ) -> bool {
137- let initialize = self . initialization_retries . check ( ) . is_ok ( ) ;
137+ fn try_initialize ( & mut self , db : & mut AnalysisDatabase , config : & Config ) -> bool {
138+ // Keep the rate limiter check as second condition when config doesn't allow it to make
139+ // sure it is not impacted.
140+ let initialize = config. enable_proc_macros && self . initialization_retries . check ( ) . is_ok ( ) ;
138141
139142 if initialize {
140143 self . spawn_server ( db) ;
@@ -176,7 +179,12 @@ impl ProcMacroClientController {
176179 self . notifier . notify :: < ProcMacroServerInitializationFailed > ( params) ;
177180 }
178181
179- fn apply_responses ( & mut self , db : & mut AnalysisDatabase , client : & ProcMacroClient ) {
182+ fn apply_responses (
183+ & mut self ,
184+ db : & mut AnalysisDatabase ,
185+ config : & Config ,
186+ client : & ProcMacroClient ,
187+ ) {
180188 let mut attribute_resolutions = Arc :: unwrap_or_clone ( db. attribute_macro_resolution ( ) ) ;
181189 let mut attribute_resolutions_changed = false ;
182190
@@ -218,7 +226,7 @@ impl ProcMacroClientController {
218226 // This must be called AFTER `client.available_responses()` is dropped, otherwise we can
219227 // deadlock.
220228 if error_occurred {
221- self . handle_error ( db) ;
229+ self . handle_error ( db, config ) ;
222230 }
223231
224232 // Set input only if resolution changed, this way we don't recompute queries if there were
0 commit comments