nushell/tests/plugins
Devyn Cairns f6faf73e02
Allow plugins to set environment variables in their caller's scope (#12204)
# Description

Adds the `AddEnvVar` plugin call, which allows plugins to set
environment variables in the caller's scope. This is the first engine
call that mutates the caller's stack, and opens the door to more
operations like this if needed.

This also comes with an extra benefit: in doing this, I needed to
refactor how context was handled, and I was able to avoid cloning
`EngineInterface` / `Stack` / `Call` in most cases that plugin calls are
used. They now only need to be cloned if the plugin call returns a
stream. The performance increase is welcome (5.5x faster on `inc`!):

```nushell
# Before
> timeit { 1..100 | each { |i| $"2.0.($i)" | inc -p } }
405ms 941µs 952ns
# After
> timeit { 1..100 | each { |i| $"2.0.($i)" | inc -p } }
73ms 68µs 749ns
```

# User-Facing Changes
- New engine call: `add_env_var()`
- Performance enhancement for plugin calls

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting
- [x] Document env manipulation in plugins guide
- [x] Document `AddEnvVar` in plugin protocol
2024-03-15 06:45:45 -05:00
..
formats Correct line folding in from ics/from vcf (#10577) 2023-10-03 19:11:16 +02:00
config.rs Allow plugins to receive configuration from the nushell configuration (#10955) 2024-01-15 16:59:47 +08:00
core_inc.rs Plugin explicit flags (#11581) 2024-01-22 15:00:43 -06:00
custom_values.rs Reorganize plugin API around commands (#12170) 2024-03-14 16:40:02 -05:00
env.rs Allow plugins to set environment variables in their caller's scope (#12204) 2024-03-15 06:45:45 -05:00
mod.rs Add environment engine calls for plugins (#12166) 2024-03-12 06:34:32 -05:00
register.rs Show plugin extra usage and search terms (#10952) 2023-11-04 15:12:58 -05:00
stream.rs MsgPack deserializer: improve handling of EOF (#12183) 2024-03-13 06:49:53 -05:00