mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 06:58:36 +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:
@ -20,7 +20,7 @@ pub trait PluginExecutionContext: Send + Sync {
|
||||
/// The pipeline externals state, for tracking the foreground process group, if present
|
||||
fn pipeline_externals_state(&self) -> Option<&Arc<(AtomicU32, AtomicU32)>>;
|
||||
/// Get engine configuration
|
||||
fn get_config(&self) -> Result<Config, ShellError>;
|
||||
fn get_config(&self) -> Result<Arc<Config>, ShellError>;
|
||||
/// Get plugin configuration
|
||||
fn get_plugin_config(&self) -> Result<Option<Value>, ShellError>;
|
||||
/// Get an environment variable from `$env`
|
||||
@ -85,8 +85,8 @@ impl<'a> PluginExecutionContext for PluginExecutionCommandContext<'a> {
|
||||
Some(&self.engine_state.pipeline_externals_state)
|
||||
}
|
||||
|
||||
fn get_config(&self) -> Result<Config, ShellError> {
|
||||
Ok(nu_engine::get_config(&self.engine_state, &self.stack))
|
||||
fn get_config(&self) -> Result<Arc<Config>, ShellError> {
|
||||
Ok(self.stack.get_config(&self.engine_state))
|
||||
}
|
||||
|
||||
fn get_plugin_config(&self) -> Result<Option<Value>, ShellError> {
|
||||
@ -239,7 +239,7 @@ impl PluginExecutionContext for PluginExecutionBogusContext {
|
||||
None
|
||||
}
|
||||
|
||||
fn get_config(&self) -> Result<Config, ShellError> {
|
||||
fn get_config(&self) -> Result<Arc<Config>, ShellError> {
|
||||
Err(ShellError::NushellFailed {
|
||||
msg: "get_config not implemented on bogus".into(),
|
||||
})
|
||||
|
@ -76,7 +76,7 @@ impl Command for PluginDeclaration {
|
||||
EvaluatedCall::try_from_call(call, engine_state, stack, eval_expression)?;
|
||||
|
||||
// Get the engine config
|
||||
let engine_config = nu_engine::get_config(engine_state, stack);
|
||||
let engine_config = stack.get_config(engine_state);
|
||||
|
||||
// Get, or start, the plugin.
|
||||
let plugin = self
|
||||
|
@ -14,6 +14,7 @@ use nu_protocol::{
|
||||
ast::Operator, CustomValue, IntoSpanned, PipelineData, PluginMetadata, PluginSignature,
|
||||
ShellError, Signals, Span, Spanned, Value,
|
||||
};
|
||||
use nu_utils::SharedCow;
|
||||
use std::{
|
||||
collections::{btree_map, BTreeMap},
|
||||
sync::{mpsc, Arc, OnceLock},
|
||||
@ -1260,7 +1261,7 @@ pub(crate) fn handle_engine_call(
|
||||
|
||||
match call {
|
||||
EngineCall::GetConfig => {
|
||||
let config = Box::new(context.get_config()?);
|
||||
let config = SharedCow::from(context.get_config()?);
|
||||
Ok(EngineCallResponse::Config(config))
|
||||
}
|
||||
EngineCall::GetPluginConfig => {
|
||||
|
Reference in New Issue
Block a user