Closed MrFoxPro closed 1 year ago
Oops, the problem was in do
syntax I guess?...
This one works
let external_completer = {| spans |
{ $spans.0: { carapace $spans.0 nushell $spans | from json } } | merge {
nix: {
let index = ($spans | length | $in - 1)
if $index < 1 { } else {
with-env { NIX_GET_COMPLETIONS: $index } {
^$"($spans.0)" ($spans | skip 1)
}
| lines
| skip 1
| str trim
| parse -r '(?P<value>\S*)\s*(?P<description>.*)'
}
}
} | get ($spans.0) | each {|it| do $it}
}
do $external_completer ["nix" "edit" ".#"]
looks like we can close this maybe? :yum:
looks like we can close this maybe? yum
don't think so, at least provided examples on website are broken
oooooh this is an example in the documentation, then yeah there is an issue with it :+1:
@MrFoxPro
i do not see the do $external_completer
above in the book page, where does it come from?
*trying to see if that's a bug with Nushell or an out-of-date documentation :wink:
@amtoine My bad here, I didn't describe issue fully Basically, for make completions work, you usually perform steps:
let external_completer = {|spans|
{
$spans.0: { default_completer $spans | from json }
"mycmd": { [[value, description]; ["compl1 ", "This is compl1"]; ["compl2 ", "This is compl2"]] }
} | get $spans.0 | each {|it| do $it}
}
You will try to debug this by running in script file or in CLI, so write it like this: 3.1
let external_completer = {|spans|
{
$spans.0: { default_completer $spans | from json }
"mycmd": { [[value, description]; ["compl1 ", "This is compl1"]; ["compl2 ", "This is compl2"]] }
} | get $spans.0 | each {|it| do $it}
}
["mycmd" "compl1"] | do $external_completer
it will result in unexpected error that I've described above. 3.2 Or like this:
let external_completer = {|spans|
{
$spans.0: { default_completer $spans | from json }
"mycmd": { [[value, description]; ["compl1 ", "This is compl1"]; ["compl2 ", "This is compl2"]] }
} | get $spans.0 | each {|it| do $it}
}
do $external_completer ["mycmd" "compl1"]
That will end up with an error:
Error: nu::shell::not_a_list
× Record field used twice
╭─[/home/foxpro/craft/foxpro-nix/test.nu:2:1]
2 │ {
3 │ $spans.0: { default_completer $spans | from json }
· ────┬───
· ╰── field first defined here
4 │ "mycmd": { [[value, description]; ["compl1 ", "This is compl1"]; ["compl2 ", "This is compl2"]] }
· ───┬───
· ╰── field redefined here
5 │ } | get $spans.0 | each {|it| do $it}
╰────
So I'm not sure if it's incorrect behaviour or outdated documentation.
:question: what happens if you only take the default completion of the book without adding custom things?
:point_right: also is see there are a bunch of expected things here :yum:
Note as i do not have commands like
default_completer
, i'll simplify the test case
you are trying to run something like
let closure = {|argv|
{
$argv.0: "first arg"
"arg0": "redefinition"
} | get $argv.0 | each {|it| print $it}
}
do $closure ["arg0" "arg1"]
and i do indeed get
Error: nu::shell::not_a_list
× Record field used twice
╭─[entry nushell/nushell#6:2:1]
2 │ {
3 │ $argv.0: "first arg"
· ───┬───
· ╰── field first defined here
4 │ "arg0": "redefinition"
· ───┬──
· ╰── field redefined here
5 │ } | get $argv.0 | each {|it| print $it}
here is what i see :relieved:
"arg0"
and $argv.0
are the same the second line of the record in $closure
is a redefinition or the "arg0"
field, which is not possible
you should either
"arg0": "redefinition"
line in the record"arg0"
from the list of args, e.g. with ["arg1" "arg2"]
get
the $argv.0
, so "arg0"
is useless
you should either
"arg0": "redefinition"
line in the recordget $argv.0
to let all the lines livein the end this looks like an incorrect closure or arguments given to it? :thinking:
in the end this looks like an incorrect closure or arguments given to it? thinking
Yes, but this is how it's stated in example:
ooooh, yup then i wouldn't say the documentation is out-of-date but completely crazy :scream: :laughing:
this actually does not make any sense to me :sweat_smile:
shall we transfer this to the website? and then try to find the proper form that this closure should take and finally fix the doc? :smirk: :muscle:
I'm newbie in Nushell and don't know how it should work in first place and if it is correct implementation
Describe the bug
I tried to make custom completer according to documentation and debug it:
This result in error:
Using this in
config.nu
results in lack of any completions. This is reproducable in0.79.1
,0.80.0
,0.80.1
How to reproduce
Run this in Nushell
Expected behavior
$spans
closure variable should be accessibleScreenshots
No response
Configuration
Additional context
https://discord.com/channels/601130461678272522/1110138320404615168/1110176133820981258 No response