You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contributor-book/plugin_protocol_reference.md
+35Lines changed: 35 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,18 @@ These are messages sent from the engine to the plugin. [`Hello`](#hello) and [`S
95
95
96
96
The body of this message is a 2-tuple (array): (`id`, `call`). The engine sends unique IDs for each plugin call it makes. The ID is needed to send the [`CallResponse`](#callresponse).
97
97
98
+
#### `Metadata` plugin call
99
+
100
+
Ask the plugin to send metadata about itself. Takes no arguments. Returns [`Metadata`](#metadata-plugin-call-response) or [`Error`](#error-plugin-call-response)
101
+
102
+
Example:
103
+
104
+
```json
105
+
{
106
+
"Call": [0, "Metadata"]
107
+
}
108
+
```
109
+
98
110
#### `Signature` plugin call
99
111
100
112
Ask the plugin to send its command signatures. Takes no arguments. Returns [`Signature`](#signature-plugin-call-response) or [`Error`](#error-plugin-call-response)
@@ -584,6 +596,29 @@ Example:
584
596
}
585
597
```
586
598
599
+
#### `Metadata` plugin call response
600
+
601
+
A successful response to a [`Metadata` plugin call](#metadata-plugin-call). The body contains fields that describe the plugin, none of which are required:
|**version**| string? | The version of the plugin (not the protocol!). [SemVer](https://semver.org) is recommended, but not required. |
606
+
607
+
Example:
608
+
609
+
```json
610
+
{
611
+
"CallResponse": [
612
+
0,
613
+
{
614
+
"Metadata": {
615
+
"version": "1.2.3"
616
+
}
617
+
}
618
+
]
619
+
}
620
+
```
621
+
587
622
#### `Signature` plugin call response
588
623
589
624
A successful response to a [`Signature` plugin call](#signature-plugin-call). The body is an array of [signatures](https://docs.rs/nu-protocol/latest/nu_protocol/struct.PluginSignature.html).
Again, we use a unit struct for `LenPlugin`, but this is the recommended place to put plugin state if needed. All commands also get a reference to the plugin type. This is what we eventually pass to `serve_plugin()` in `main()`.
231
239
232
-
The only required method in `Plugin` is `commands()`, which initializes the plugin's commands. A boxed `dyn` reference is used so that we can keep all of the different command types in the single list. Dispatch by command name is automatically handled in `serve_plugin()` by looking at the name defined in the signature - in our case, that's `len`. A plugin can contain many commands, so if you end up adding more, just add them to the list returned by `commands()`.
240
+
`Plugin` has two required methods: `version()`, which reports the plugin's version back to Nu, and `commands()`, which initializes the plugin's commands. A boxed `dyn` reference is used so that we can keep all of the different command types in the single list. Dispatch by command name is automatically handled in `serve_plugin()` by looking at the name defined in the signature - in our case, that's `len`. A plugin can contain many commands, so if you end up adding more, just add them to the list returned by `commands()`.
241
+
242
+
For the version, we just use the `CARGO_PKG_VERSION` environment variable available at compile-time in order to get our plugin's version from Cargo.
233
243
234
244
Lastly, let's look at the top of the file:
235
245
@@ -402,6 +412,10 @@ use nu_protocol::{Signature, Type, Value};
0 commit comments