nushell/crates/nu-protocol/src
Devyn Cairns f3843a6176
Make plugins able to find and call other commands (#13407)
# Description

Adds functionality to the plugin interface to support calling internal
commands from plugins. For example, using `view ir --json`:

```rust
let closure: Value = call.req(0)?;

let Some(decl_id) = engine.find_decl("view ir")? else {
    return Err(LabeledError::new("`view ir` not found"));
};

let ir_json = engine.call_decl(
    decl_id,
    EvaluatedCall::new(call.head)
        .with_named("json".into_spanned(call.head), Value::bool(true, call.head))
        .with_positional(closure),
    PipelineData::Empty,
    true,
    false,
)?.into_value()?.into_string()?;

let ir = serde_json::from_value(&ir_json);

// ...
```

# User-Facing Changes

Plugin developers can now use `EngineInterface::find_decl()` and
`call_decl()` to call internal commands, which could be handy for
formatters like `to csv` or `to nuon`, or for reflection commands that
help gain insight into the engine.

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

# After Submitting
- [ ] release notes
- [ ] update plugin protocol documentation: `FindDecl`, `CallDecl`
engine calls; `Identifier` engine call response
2024-07-19 13:54:21 +08:00
..
ast Overhaul $in expressions (#13357) 2024-07-17 16:02:42 -05:00
config Document public types in nu-protocol (#12906) 2024-07-11 13:30:12 +02:00
debugger Overhaul $in expressions (#13357) 2024-07-17 16:02:42 -05:00
engine Remove unused field in StateWorkingSet (#13387) 2024-07-16 11:28:31 +02:00
errors Deprecate group in favor of chunks (#13377) 2024-07-16 03:49:00 +00:00
ir Make plugins able to find and call other commands (#13407) 2024-07-19 13:54:21 +08:00
pipeline Deprecate group in favor of chunks (#13377) 2024-07-16 03:49:00 +00:00
plugin remove the deprecated register command (#13297) 2024-07-05 07:16:50 -05:00
process Document public types in nu-protocol (#12906) 2024-07-11 13:30:12 +02:00
value Document public types in nu-protocol (#12906) 2024-07-11 13:30:12 +02:00
alias.rs Document public types in nu-protocol (#12906) 2024-07-11 13:30:12 +02:00
did_you_mean.rs Improve case insensitivity consistency (#10884) 2023-11-08 23:58:54 +01:00
eval_base.rs Overhaul $in expressions (#13357) 2024-07-17 16:02:42 -05:00
eval_const.rs Overhaul $in expressions (#13357) 2024-07-17 16:02:42 -05:00
example.rs Overhaul the plugin cache file with a new msgpack+brotli format (#12579) 2024-04-21 07:36:26 -05:00
id.rs Internal representation (IR) compiler and evaluator (#13330) 2024-07-10 17:33:59 -07:00
lev_distance.rs Rework for new clippy lints (#12736) 2024-05-02 19:29:03 +02:00
lib.rs Add top-level crate documentation/READMEs (#12907) 2024-07-14 10:10:41 +02:00
module.rs Enable reloading changes to a submodule (#13170) 2024-06-25 18:33:37 -07:00
parser_path.rs Enable reloading changes to a submodule (#13170) 2024-06-25 18:33:37 -07:00
signature.rs Document public types in nu-protocol (#12906) 2024-07-11 13:30:12 +02:00
span.rs Document public types in nu-protocol (#12906) 2024-07-11 13:30:12 +02:00
syntax_shape.rs open, rm, umv, cp, rm and du: Don't globs if inputs are variables or string interpolation (#11886) 2024-02-23 09:17:09 +08:00
ty.rs Deprecate group in favor of chunks (#13377) 2024-07-16 03:49:00 +00:00