PR feedback changes

This commit is contained in:
Jack Wright 2024-08-01 11:23:15 -07:00
parent 88a8ad9da6
commit dcf7ea84e0
3 changed files with 55 additions and 49 deletions

View File

@ -7,7 +7,7 @@
# language without adding any extra dependencies to our tests. # language without adding any extra dependencies to our tests.
const NUSHELL_VERSION = "0.96.2" const NUSHELL_VERSION = "0.96.2"
const PLUGIN_VERSION = "0.1.0" # bump if you change commands! const PLUGIN_VERSION = "0.1.1" # bump if you change commands!
def main [--stdio] { def main [--stdio] {
if ($stdio) { if ($stdio) {
@ -133,7 +133,7 @@ def process_call [
# Create a Value of type List that will be encoded and sent to Nushell # Create a Value of type List that will be encoded and sent to Nushell
let value = { let value = {
Value: { value: { Value: [{
List: { List: {
vals: (0..9 | each { |x| vals: (0..9 | each { |x|
{ {
@ -157,8 +157,7 @@ def process_call [
}), }),
span: $span span: $span
} }
} }, null]
}
} }
write_response $id { PipelineData: $value } write_response $id { PipelineData: $value }

View File

@ -28,7 +28,7 @@ import json
NUSHELL_VERSION = "0.96.2" NUSHELL_VERSION = "0.96.2"
PLUGIN_VERSION = "0.1.0" # bump if you change commands! PLUGIN_VERSION = "0.1.1" # bump if you change commands!
def signatures(): def signatures():
@ -125,15 +125,12 @@ def process_call(id, plugin_call):
span = plugin_call["call"]["head"] span = plugin_call["call"]["head"]
# Creates a Value of type List that will be encoded and sent to Nushell # Creates a Value of type List that will be encoded and sent to Nushell
def f(x, y): return { def f(x, y):
"Int": { return {"Int": {"val": x * y, "span": span}}
"val": x * y,
"span": span
}
}
value = { value = {
"Value": { "Value": [
{
"List": { "List": {
"vals": [ "vals": [
{ {
@ -143,13 +140,16 @@ def process_call(id, plugin_call):
"two": f(x, 1), "two": f(x, 1),
"three": f(x, 2), "three": f(x, 2),
}, },
"span": span "span": span,
} }
} for x in range(0, 10) }
for x in range(0, 10)
], ],
"span": span "span": span,
}
} }
},
None,
]
} }
write_response(id, {"PipelineData": value}) write_response(id, {"PipelineData": value})
@ -172,7 +172,7 @@ def tell_nushell_hello():
"Hello": { "Hello": {
"protocol": "nu-plugin", # always this value "protocol": "nu-plugin", # always this value
"version": NUSHELL_VERSION, "version": NUSHELL_VERSION,
"features": [] "features": [],
} }
} }
sys.stdout.write(json.dumps(hello)) sys.stdout.write(json.dumps(hello))
@ -200,7 +200,8 @@ def write_error(id, text, span=None):
Use this error format to send errors to nushell in response to a plugin call. The ID of the Use this error format to send errors to nushell in response to a plugin call. The ID of the
plugin call is required. plugin call is required.
""" """
error = { error = (
{
"Error": { "Error": {
"msg": "ERROR from plugin", "msg": "ERROR from plugin",
"labels": [ "labels": [
@ -210,12 +211,15 @@ def write_error(id, text, span=None):
} }
], ],
} }
} if span is not None else { }
if span is not None
else {
"Error": { "Error": {
"msg": "ERROR from plugin", "msg": "ERROR from plugin",
"help": text, "help": text,
} }
} }
)
write_response(id, error) write_response(id, error)
@ -230,11 +234,14 @@ def handle_input(input):
elif "Call" in input: elif "Call" in input:
[id, plugin_call] = input["Call"] [id, plugin_call] = input["Call"]
if plugin_call == "Metadata": if plugin_call == "Metadata":
write_response(id, { write_response(
id,
{
"Metadata": { "Metadata": {
"version": PLUGIN_VERSION, "version": PLUGIN_VERSION,
} }
}) },
)
elif plugin_call == "Signature": elif plugin_call == "Signature":
write_response(id, signatures()) write_response(id, signatures())
elif "Run" in plugin_call: elif "Run" in plugin_call:

View File

@ -178,7 +178,7 @@ fn handle_message(
id, id,
{ {
"PipelineData": { "PipelineData": {
"Value": {"value": return_value} "Value": [return_value, None::<Value>]
} }
} }
] ]