Unnamed repository; edit this file 'description' to name the repository.
Apply requested changes round 3
Ali Bektas 2024-06-05
parent cf97aac · commit 75409f7
-rw-r--r--crates/rust-analyzer/src/bin/main.rs6
-rw-r--r--crates/rust-analyzer/src/cli/scip.rs8
-rw-r--r--crates/rust-analyzer/src/config.rs29
-rw-r--r--crates/rust-analyzer/src/global_state.rs4
-rw-r--r--crates/rust-analyzer/src/handlers/notification.rs7
-rw-r--r--crates/rust-analyzer/src/reload.rs7
-rw-r--r--crates/rust-analyzer/tests/slow-tests/support.rs6
7 files changed, 36 insertions, 31 deletions
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index 316384f963..545ed6d186 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -228,8 +228,10 @@ fn run_server() -> anyhow::Result<()> {
if let Some(json) = initialization_options {
let mut change = ConfigChange::default();
change.change_client_config(json);
- let mut error_sink = ConfigError::default();
- (config, _) = config.apply_change(change, &mut error_sink);
+
+ let error_sink: ConfigError;
+ (config, error_sink, _) = config.apply_change(change);
+
if !error_sink.is_empty() {
use lsp_types::{
notification::{Notification, ShowMessage},
diff --git a/crates/rust-analyzer/src/cli/scip.rs b/crates/rust-analyzer/src/cli/scip.rs
index d73e4028e5..8f60b17b59 100644
--- a/crates/rust-analyzer/src/cli/scip.rs
+++ b/crates/rust-analyzer/src/cli/scip.rs
@@ -14,7 +14,7 @@ use tracing::error;
use crate::{
cli::flags,
- config::{ConfigChange, ConfigError},
+ config::ConfigChange,
line_index::{LineEndings, LineIndex, PositionEncoding},
};
@@ -45,8 +45,10 @@ impl flags::Scip {
let json = serde_json::from_reader(&mut file)?;
let mut change = ConfigChange::default();
change.change_client_config(json);
- let mut error_sink = ConfigError::default();
- (config, _) = config.apply_change(change, &mut error_sink);
+
+ let error_sink;
+ (config, error_sink, _) = config.apply_change(change);
+
// FIXME @alibektas : What happens to errors without logging?
error!(?error_sink, "Config Error(s)");
}
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 646bae4467..8a3a9c7efb 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -705,7 +705,7 @@ impl Config {
// FIXME @alibektas : Server's health uses error sink but in other places it is not used atm.
/// Changes made to client and global configurations will partially not be reflected even after `.apply_change()` was called.
/// The return tuple's bool component signals whether the `GlobalState` should call its `update_configuration()` method.
- pub fn apply_change(
+ fn apply_change_with_sink(
&self,
change: ConfigChange,
error_sink: &mut ConfigError,
@@ -809,10 +809,13 @@ impl Config {
(config, should_update)
}
- pub fn apply_change_whatever(&self, change: ConfigChange) -> (Config, ConfigError) {
+ /// Given `change` this generates a new `Config`, thereby collecting errors of type `ConfigError`.
+ /// If there are changes that have global/client level effect, the last component of the return type
+ /// will be set to `true`, which should be used by the `GlobalState` to update itself.
+ pub fn apply_change(&self, change: ConfigChange) -> (Config, ConfigError, bool) {
let mut e = ConfigError(vec![]);
- let (config, _) = self.apply_change(change, &mut e);
- (config, e)
+ let (config, should_update) = self.apply_change_with_sink(change, &mut e);
+ (config, e, should_update)
}
}
@@ -3300,8 +3303,7 @@ mod tests {
"server": null,
}}));
- let mut error_sink = ConfigError::default();
- (config, _) = config.apply_change(change, &mut error_sink);
+ (config, _, _) = config.apply_change(change);
assert_eq!(config.proc_macro_srv(), None);
}
@@ -3320,8 +3322,7 @@ mod tests {
"server": project_root().display().to_string(),
}}));
- let mut error_sink = ConfigError::default();
- (config, _) = config.apply_change(change, &mut error_sink);
+ (config, _, _) = config.apply_change(change);
assert_eq!(config.proc_macro_srv(), Some(AbsPathBuf::try_from(project_root()).unwrap()));
}
@@ -3342,8 +3343,7 @@ mod tests {
"server": "./server"
}}));
- let mut error_sink = ConfigError::default();
- (config, _) = config.apply_change(change, &mut error_sink);
+ (config, _, _) = config.apply_change(change);
assert_eq!(
config.proc_macro_srv(),
@@ -3367,8 +3367,7 @@ mod tests {
"rust" : { "analyzerTargetDir" : null }
}));
- let mut error_sink = ConfigError::default();
- (config, _) = config.apply_change(change, &mut error_sink);
+ (config, _, _) = config.apply_change(change);
assert_eq!(config.cargo_targetDir(), &None);
assert!(
matches!(config.flycheck(), FlycheckConfig::CargoCommand { options, .. } if options.target_dir.is_none())
@@ -3390,8 +3389,7 @@ mod tests {
"rust" : { "analyzerTargetDir" : true }
}));
- let mut error_sink = ConfigError::default();
- (config, _) = config.apply_change(change, &mut error_sink);
+ (config, _, _) = config.apply_change(change);
assert_eq!(config.cargo_targetDir(), &Some(TargetDirectory::UseSubdirectory(true)));
assert!(
@@ -3414,8 +3412,7 @@ mod tests {
"rust" : { "analyzerTargetDir" : "other_folder" }
}));
- let mut error_sink = ConfigError::default();
- (config, _) = config.apply_change(change, &mut error_sink);
+ (config, _, _) = config.apply_change(change);
assert_eq!(
config.cargo_targetDir(),
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index c289a07978..5e7e8061ef 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -404,8 +404,8 @@ impl GlobalState {
change
};
- let mut error_sink = ConfigError::default();
- let (config, should_update) = self.config.apply_change(config_change, &mut error_sink);
+
+ let (config, _, should_update) = self.config.apply_change(config_change);
if should_update {
self.update_configuration(config);
diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs
index bdb27043eb..5048904430 100644
--- a/crates/rust-analyzer/src/handlers/notification.rs
+++ b/crates/rust-analyzer/src/handlers/notification.rs
@@ -13,7 +13,7 @@ use triomphe::Arc;
use vfs::{AbsPathBuf, ChangeKind, VfsPath};
use crate::{
- config::{Config, ConfigChange, ConfigError},
+ config::{Config, ConfigChange},
global_state::GlobalState,
lsp::{from_proto, utils::apply_document_changes},
lsp_ext::{self, RunFlycheckParams},
@@ -200,8 +200,9 @@ pub(crate) fn handle_did_change_configuration(
let mut config = Config::clone(&*this.config);
let mut change = ConfigChange::default();
change.change_client_config(json.take());
- let mut error_sink = ConfigError::default();
- (config, _) = config.apply_change(change, &mut error_sink);
+
+ (config, _, _) = config.apply_change(change);
+
// Client config changes neccesitates .update_config method to be called.
this.update_configuration(config);
}
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 364a0083e5..6061ccbfe8 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -33,7 +33,7 @@ use triomphe::Arc;
use vfs::{AbsPath, AbsPathBuf, ChangeKind};
use crate::{
- config::{Config, ConfigChange, ConfigError, FilesWatcher, LinkedProject},
+ config::{Config, ConfigChange, FilesWatcher, LinkedProject},
global_state::GlobalState,
lsp_ext,
main_loop::Task,
@@ -604,8 +604,9 @@ impl GlobalState {
let mut config_change = ConfigChange::default();
config_change.change_source_root_parent_map(self.local_roots_parent_map.clone());
- let mut error_sink = ConfigError::default();
- let (config, _) = self.config.apply_change(config_change, &mut error_sink);
+
+ let (config, _, _) = self.config.apply_change(config_change);
+
self.config = Arc::new(config);
self.recreate_crate_graph(cause);
diff --git a/crates/rust-analyzer/tests/slow-tests/support.rs b/crates/rust-analyzer/tests/slow-tests/support.rs
index d12d0be539..2d9b3d560b 100644
--- a/crates/rust-analyzer/tests/slow-tests/support.rs
+++ b/crates/rust-analyzer/tests/slow-tests/support.rs
@@ -206,9 +206,11 @@ impl Project<'_> {
let mut change = ConfigChange::default();
change.change_client_config(self.config);
- let mut error_sink = ConfigError::default();
+
+ let error_sink: ConfigError;
+ (config, error_sink, _) = config.apply_change(change);
assert!(error_sink.is_empty(), "{error_sink:?}");
- (config, _) = config.apply_change(change, &mut error_sink);
+
config.rediscover_workspaces();
Server::new(tmp_dir.keep(), config)