mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
Update config directly at assignment (#13332)
# Description Allows `Stack` to have a modified local `Config`, which is updated immediately when `$env.config` is assigned to. This means that even within a script, commands that come after `$env.config` changes will always see those changes in `Stack::get_config()`. Also fixed a lot of cases where `engine_state.get_config()` was used even when `Stack` was available. Closes #13324. # User-Facing Changes - Config changes apply immediately after the assignment is executed, rather than whenever config is read by a command that needs it. - Potentially slower performance when executing a lot of lines that change `$env.config` one after another. Recommended to get `$env.config` into a `mut` variable first and do modifications, then assign it back. - Much faster performance when executing a script that made modifications to `$env.config`, as the changes are only parsed once. # Tests + Formatting All passing. # After Submitting - [ ] release notes
This commit is contained in:
@ -15,6 +15,7 @@ nu-engine = { path = "../nu-engine", version = "0.95.1" }
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.95.1" }
|
||||
nu-plugin-protocol = { path = "../nu-plugin-protocol", version = "0.95.1" }
|
||||
nu-plugin-core = { path = "../nu-plugin-core", version = "0.95.1", default-features = false }
|
||||
nu-utils = { path = "../nu-utils", version = "0.95.1" }
|
||||
|
||||
log = { workspace = true }
|
||||
thiserror = "1.0"
|
||||
@ -29,4 +30,4 @@ local-socket = ["nu-plugin-core/local-socket"]
|
||||
|
||||
[target.'cfg(target_family = "unix")'.dependencies]
|
||||
# For setting the process group ID (EnterForeground / LeaveForeground)
|
||||
nix = { workspace = true, default-features = false, features = ["process"] }
|
||||
nix = { workspace = true, default-features = false, features = ["process"] }
|
||||
|
@ -14,6 +14,7 @@ use nu_protocol::{
|
||||
engine::Closure, Config, LabeledError, PipelineData, PluginMetadata, PluginSignature,
|
||||
ShellError, Signals, Span, Spanned, Value,
|
||||
};
|
||||
use nu_utils::SharedCow;
|
||||
use std::{
|
||||
collections::{btree_map, BTreeMap, HashMap},
|
||||
sync::{mpsc, Arc},
|
||||
@ -525,9 +526,9 @@ impl EngineInterface {
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn get_config(&self) -> Result<Box<Config>, ShellError> {
|
||||
pub fn get_config(&self) -> Result<Arc<Config>, ShellError> {
|
||||
match self.engine_call(EngineCall::GetConfig)? {
|
||||
EngineCallResponse::Config(config) => Ok(config),
|
||||
EngineCallResponse::Config(config) => Ok(SharedCow::into_arc(config)),
|
||||
EngineCallResponse::Error(err) => Err(err),
|
||||
_ => Err(ShellError::PluginFailedToDecode {
|
||||
msg: "Received unexpected response for EngineCall::GetConfig".into(),
|
||||
|
@ -670,7 +670,7 @@ fn print_help(plugin: &impl Plugin, encoder: impl PluginEncoder) {
|
||||
}
|
||||
})
|
||||
.and_then(|_| {
|
||||
let flags = get_flags_section(None, &signature, |v| format!("{:#?}", v));
|
||||
let flags = get_flags_section(None, None, &signature, |v| format!("{:#?}", v));
|
||||
write!(help, "{flags}")
|
||||
})
|
||||
.and_then(|_| writeln!(help, "\nParameters:"))
|
||||
|
Reference in New Issue
Block a user