Skip to content

Commit 1d1273f

Browse files
authored
Book docs for recent plugin changes (#1318)
* stream_example cleanup * LabeledError changes * GetHelp * Docs for plugin testing * misc fix * Plugin command API changes * Fix location of LabeledError
1 parent cd6c78b commit 1d1273f

File tree

3 files changed

+223
-69
lines changed

3 files changed

+223
-69
lines changed

book/plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ $env.config.plugin_gc = {
133133
inc: {
134134
stop_after: 0sec # stop as soon as possible
135135
}
136-
stream_example: {
136+
example: {
137137
enabled: false # never stop automatically
138138
}
139139
}

contributor-book/plugin_protocol_reference.md

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,23 @@ These are messages sent from the plugin to the engine. [`Hello`](#hello) and [`S
511511

512512
An error occurred while attempting to fulfill the request.
513513

514-
| Field | Type | Usage |
515-
| --------- | ----------------------- | ------------------------------------------------------------------------------------ |
516-
| **label** | string | The main error message to show at the top of the error. |
517-
| **msg** | string | Additional context for the error. If `span` is provided, `msg` points at the `span`. |
518-
| **span** | [`Span`](#span) or null | The span that points to what source code caused the error. |
514+
| Field | Type | Usage |
515+
| ---------- | --------------------- | -------------------------------------------------------------------------------------------------------------- |
516+
| **msg** | string | The main error message to show at the top of the error. |
517+
| **labels** | `ErrorLabel` array? | Spans and messages to label the error in the source code. |
518+
| **code** | string? | A unique machine- and search-friendly code that can be matched against, e.g. `nu::shell::missing_config_value` |
519+
| **url** | string? | A URL that links to additional information about the error. |
520+
| **help** | string? | Additional help for the error, usually a hint about what the user might try. |
521+
| **inner** | `LabeledError` array? | Additional errors referenced by the error, possibly the cause(s) of this error. |
522+
523+
Most of the fields are not required - only `msg` must be present. `ErrorLabel` (in the `labels` array) is as follows:
524+
525+
| Field | Type | Usage |
526+
| -------- | --------------- | ----------------------------------------------------------- |
527+
| **text** | string | The message for the label. |
528+
| **span** | [`Span`](#span) | The span in the source code that the label should point to. |
529+
530+
It is strongly preferred to provide labeled messages whenever possible to let the user know where the problem might be in their script. If there is no more suitable span from a value that can be used, `head` from [`EvaluatedCall`](#evaluatedcall) is a good fallback.
519531

520532
Example:
521533

@@ -525,12 +537,24 @@ Example:
525537
0,
526538
{
527539
"Error": {
528-
"label": "A really bad error occurred",
529-
"msg": "I don't know, but it's over nine thousand!",
530-
"span": {
531-
"start": 9001,
532-
"end": 9007
533-
}
540+
"msg": "A really bad error occurred",
541+
"labels": [
542+
{
543+
"text": "I don't know, but it's over nine thousand!",
544+
"span": {
545+
"start": 9001,
546+
"end": 9007
547+
}
548+
}
549+
],
550+
"code": "my_plugin::bad::really_bad",
551+
"url": "https://example.org/my_plugin/error/bad/really_bad.html",
552+
"help": "you can solve this by not doing the bad thing",
553+
"inner": [
554+
{
555+
"msg": "The bad thing"
556+
}
557+
]
534558
}
535559
}
536560
]
@@ -777,6 +801,22 @@ Example:
777801
}
778802
```
779803

804+
#### `GetHelp` engine call
805+
806+
Get fully formatted help text for the current command. This can help with implementing top-level commands that just list their subcommands, rather than implementing any specific functionality. The response on success is [`Value` pipeline data](#pipelinedataheader-value) that always contains a string.
807+
808+
Example:
809+
810+
```json
811+
{
812+
"EngineCall": {
813+
"context": 1,
814+
"id": 2,
815+
"call": "GetHelp"
816+
}
817+
}
818+
```
819+
780820
#### `EvalClosure` engine call
781821

782822
Pass a [`Closure`](#closure) and arguments to the engine to be evaluated. Returns a [`PipelineData` response](#pipelinedata-engine-call-response) if successful with the output of the closure, which may be a stream.

0 commit comments

Comments
 (0)