Skip to content

Commit 861713e

Browse files
committed
Apply requested changes round 3
1 parent 09c9963 commit 861713e

File tree

7 files changed

+36
-31
lines changed

7 files changed

+36
-31
lines changed

crates/rust-analyzer/src/bin/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ fn run_server() -> anyhow::Result<()> {
228228
if let Some(json) = initialization_options {
229229
let mut change = ConfigChange::default();
230230
change.change_client_config(json);
231-
let mut error_sink = ConfigError::default();
232-
(config, _) = config.apply_change(change, &mut error_sink);
231+
232+
let error_sink: ConfigError;
233+
(config, error_sink, _) = config.apply_change(change);
234+
233235
if !error_sink.is_empty() {
234236
use lsp_types::{
235237
notification::{Notification, ShowMessage},

crates/rust-analyzer/src/cli/scip.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tracing::error;
1414

1515
use crate::{
1616
cli::flags,
17-
config::{ConfigChange, ConfigError},
17+
config::ConfigChange,
1818
line_index::{LineEndings, LineIndex, PositionEncoding},
1919
};
2020

@@ -45,8 +45,10 @@ impl flags::Scip {
4545
let json = serde_json::from_reader(&mut file)?;
4646
let mut change = ConfigChange::default();
4747
change.change_client_config(json);
48-
let mut error_sink = ConfigError::default();
49-
(config, _) = config.apply_change(change, &mut error_sink);
48+
49+
let error_sink;
50+
(config, error_sink, _) = config.apply_change(change);
51+
5052
// FIXME @alibektas : What happens to errors without logging?
5153
error!(?error_sink, "Config Error(s)");
5254
}

crates/rust-analyzer/src/config.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ impl Config {
701701
// FIXME @alibektas : Server's health uses error sink but in other places it is not used atm.
702702
/// Changes made to client and global configurations will partially not be reflected even after `.apply_change()` was called.
703703
/// The return tuple's bool component signals whether the `GlobalState` should call its `update_configuration()` method.
704-
pub fn apply_change(
704+
fn apply_change_with_sink(
705705
&self,
706706
change: ConfigChange,
707707
error_sink: &mut ConfigError,
@@ -805,10 +805,13 @@ impl Config {
805805
(config, should_update)
806806
}
807807

808-
pub fn apply_change_whatever(&self, change: ConfigChange) -> (Config, ConfigError) {
808+
/// Given `change` this generates a new `Config`, thereby collecting errors of type `ConfigError`.
809+
/// If there are changes that have global/client level effect, the last component of the return type
810+
/// will be set to `true`, which should be used by the `GlobalState` to update itself.
811+
pub fn apply_change(&self, change: ConfigChange) -> (Config, ConfigError, bool) {
809812
let mut e = ConfigError(vec![]);
810-
let (config, _) = self.apply_change(change, &mut e);
811-
(config, e)
813+
let (config, should_update) = self.apply_change_with_sink(change, &mut e);
814+
(config, e, should_update)
812815
}
813816
}
814817

@@ -3293,8 +3296,7 @@ mod tests {
32933296
"server": null,
32943297
}}));
32953298

3296-
let mut error_sink = ConfigError::default();
3297-
(config, _) = config.apply_change(change, &mut error_sink);
3299+
(config, _, _) = config.apply_change(change);
32983300
assert_eq!(config.proc_macro_srv(), None);
32993301
}
33003302

@@ -3313,8 +3315,7 @@ mod tests {
33133315
"server": project_root().display().to_string(),
33143316
}}));
33153317

3316-
let mut error_sink = ConfigError::default();
3317-
(config, _) = config.apply_change(change, &mut error_sink);
3318+
(config, _, _) = config.apply_change(change);
33183319
assert_eq!(config.proc_macro_srv(), Some(AbsPathBuf::try_from(project_root()).unwrap()));
33193320
}
33203321

@@ -3335,8 +3336,7 @@ mod tests {
33353336
"server": "./server"
33363337
}}));
33373338

3338-
let mut error_sink = ConfigError::default();
3339-
(config, _) = config.apply_change(change, &mut error_sink);
3339+
(config, _, _) = config.apply_change(change);
33403340

33413341
assert_eq!(
33423342
config.proc_macro_srv(),
@@ -3360,8 +3360,7 @@ mod tests {
33603360
"rust" : { "analyzerTargetDir" : null }
33613361
}));
33623362

3363-
let mut error_sink = ConfigError::default();
3364-
(config, _) = config.apply_change(change, &mut error_sink);
3363+
(config, _, _) = config.apply_change(change);
33653364
assert_eq!(config.cargo_targetDir(), &None);
33663365
assert!(
33673366
matches!(config.flycheck(), FlycheckConfig::CargoCommand { options, .. } if options.target_dir.is_none())
@@ -3383,8 +3382,7 @@ mod tests {
33833382
"rust" : { "analyzerTargetDir" : true }
33843383
}));
33853384

3386-
let mut error_sink = ConfigError::default();
3387-
(config, _) = config.apply_change(change, &mut error_sink);
3385+
(config, _, _) = config.apply_change(change);
33883386

33893387
assert_eq!(config.cargo_targetDir(), &Some(TargetDirectory::UseSubdirectory(true)));
33903388
assert!(
@@ -3407,8 +3405,7 @@ mod tests {
34073405
"rust" : { "analyzerTargetDir" : "other_folder" }
34083406
}));
34093407

3410-
let mut error_sink = ConfigError::default();
3411-
(config, _) = config.apply_change(change, &mut error_sink);
3408+
(config, _, _) = config.apply_change(change);
34123409

34133410
assert_eq!(
34143411
config.cargo_targetDir(),

crates/rust-analyzer/src/global_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ impl GlobalState {
435435

436436
change
437437
};
438-
let mut error_sink = ConfigError::default();
439-
let (config, should_update) = self.config.apply_change(config_change, &mut error_sink);
438+
439+
let (config, _, should_update) = self.config.apply_change(config_change);
440440

441441
if should_update {
442442
self.update_configuration(config);

crates/rust-analyzer/src/handlers/notification.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use triomphe::Arc;
1313
use vfs::{AbsPathBuf, ChangeKind, VfsPath};
1414

1515
use crate::{
16-
config::{Config, ConfigChange, ConfigError},
16+
config::{Config, ConfigChange},
1717
global_state::GlobalState,
1818
lsp::{from_proto, utils::apply_document_changes},
1919
lsp_ext::{self, RunFlycheckParams},
@@ -200,8 +200,9 @@ pub(crate) fn handle_did_change_configuration(
200200
let mut config = Config::clone(&*this.config);
201201
let mut change = ConfigChange::default();
202202
change.change_client_config(json.take());
203-
let mut error_sink = ConfigError::default();
204-
(config, _) = config.apply_change(change, &mut error_sink);
203+
204+
(config, _, _) = config.apply_change(change);
205+
205206
// Client config changes neccesitates .update_config method to be called.
206207
this.update_configuration(config);
207208
}

crates/rust-analyzer/src/reload.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use triomphe::Arc;
3333
use vfs::{AbsPath, AbsPathBuf, ChangeKind};
3434

3535
use crate::{
36-
config::{Config, ConfigChange, ConfigError, FilesWatcher, LinkedProject},
36+
config::{Config, ConfigChange, FilesWatcher, LinkedProject},
3737
global_state::GlobalState,
3838
lsp_ext,
3939
main_loop::Task,
@@ -621,8 +621,9 @@ impl GlobalState {
621621

622622
let mut config_change = ConfigChange::default();
623623
config_change.change_source_root_parent_map(self.local_roots_parent_map.clone());
624-
let mut error_sink = ConfigError::default();
625-
let (config, _) = self.config.apply_change(config_change, &mut error_sink);
624+
625+
let (config, _, _) = self.config.apply_change(config_change);
626+
626627
self.config = Arc::new(config);
627628

628629
self.recreate_crate_graph(cause);

crates/rust-analyzer/tests/slow-tests/support.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,11 @@ impl Project<'_> {
206206
let mut change = ConfigChange::default();
207207

208208
change.change_client_config(self.config);
209-
let mut error_sink = ConfigError::default();
209+
210+
let error_sink: ConfigError;
211+
(config, error_sink, _) = config.apply_change(change);
210212
assert!(error_sink.is_empty(), "{error_sink:?}");
211-
(config, _) = config.apply_change(change, &mut error_sink);
213+
212214
config.rediscover_workspaces();
213215

214216
Server::new(tmp_dir.keep(), config)

0 commit comments

Comments
 (0)