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:
Devyn Cairns
2024-07-11 06:09:33 -07:00
committed by GitHub
parent deaa711ca6
commit f65bc97a54
46 changed files with 327 additions and 222 deletions

View File

@ -64,8 +64,8 @@ fn convert_value_to_string(
let has_no_head = cols.is_empty() || (cols.len() == 1 && cols[0].is_empty());
let has_single_value = vals.len() == 1 && vals[0].len() == 1;
if !has_no_head && has_single_value {
let config = engine_state.get_config();
Ok(vals[0][0].to_abbreviated_string(config))
let config = stack.get_config(engine_state);
Ok(vals[0][0].to_abbreviated_string(&config))
} else {
let config = engine_state.get_config();
let style_computer = StyleComputer::from_config(engine_state, stack);

View File

@ -63,10 +63,10 @@ impl Command for Explore {
let tail: bool = call.has_flag(engine_state, stack, "tail")?;
let peek_value: bool = call.has_flag(engine_state, stack, "peek")?;
let nu_config = engine_state.get_config();
let nu_config = stack.get_config(engine_state);
let style_computer = StyleComputer::from_config(engine_state, stack);
let mut explore_config = ExploreConfig::from_nu_config(nu_config);
let mut explore_config = ExploreConfig::from_nu_config(&nu_config);
explore_config.table.show_header = show_head;
explore_config.table.show_index = show_index;
explore_config.table.separator_style = lookup_color(&style_computer, "separator");
@ -74,7 +74,7 @@ impl Command for Explore {
let lscolors = create_lscolors(engine_state, stack);
let config = PagerConfig::new(
nu_config,
&nu_config,
&explore_config,
&style_computer,
&lscolors,