Git Product home page Git Product logo

Comments (11)

MrFoxPro avatar MrFoxPro commented on August 11, 2024

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" ".#"]

from nushell.github.io.

amtoine avatar amtoine commented on August 11, 2024

looks like we can close this maybe? ๐Ÿ˜‹

from nushell.github.io.

MrFoxPro avatar MrFoxPro commented on August 11, 2024

looks like we can close this maybe? yum

don't think so, at least provided examples on website are broken

from nushell.github.io.

amtoine avatar amtoine commented on August 11, 2024

oooooh this is an example in the documentation, then yeah there is an issue with it ๐Ÿ‘

from nushell.github.io.

amtoine avatar amtoine commented on August 11, 2024

@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 ๐Ÿ˜‰

from nushell.github.io.

MrFoxPro avatar MrFoxPro commented on August 11, 2024

@amtoine
My bad here, I didn't describe issue fully
Basically, for make completions work, you usually perform steps:

  1. Look at docs, take example and add personal custom completions in config.nu:
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}
}
  1. And this will make completions go away completely.
  2. 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.

from nushell.github.io.

amtoine avatar amtoine commented on August 11, 2024

โ“ what happens if you only take the default completion of the book without adding custom things?

๐Ÿ‘‰ also is see there are a bunch of expected things here ๐Ÿ˜‹

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 ๐Ÿ˜Œ

  • as "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
    • remove the "arg0": "redefinition" line in the record
    • remove "arg0" from the list of args, e.g. with ["arg1" "arg2"]
  • you define a record with a bunch of of field and then only get the $argv.0, so "arg0" is useless
    you should either
    • remove the "arg0": "redefinition" line in the record
    • remove the get $argv.0 to let all the lines live

in the end this looks like an incorrect closure or arguments given to it? ๐Ÿค”

from nushell.github.io.

MrFoxPro avatar MrFoxPro commented on August 11, 2024

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:
image

from nushell.github.io.

amtoine avatar amtoine commented on August 11, 2024

ooooh, yup
then i wouldn't say the documentation is out-of-date but completely crazy ๐Ÿ˜ฑ ๐Ÿ˜†

this actually does not make any sense to me ๐Ÿ˜…

from nushell.github.io.

amtoine avatar amtoine commented on August 11, 2024

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? ๐Ÿ˜ ๐Ÿ’ช

from nushell.github.io.

MrFoxPro avatar MrFoxPro commented on August 11, 2024

I'm newbie in Nushell and don't know how it should work in first place and if it is correct implementation

from nushell.github.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.