Skip to content

Nushell completers in env.nu use the deprecated positional completer input #3127

Open

Description

@naokihaba

Describe the bug

The Nushell completers in the generated env.nu receive their input as a positional parameter:

def "nu-complete vp" [context: string] { ... }
def "nu-complete vpr" [context: string] { ... }

Nushell 0.116 gives a completer one record with the fields token, place, and buffer, and it deprecates a positional parameter such as context. The first Tab completion of vp in a new Nushell session shows a nu::shell::deprecated warning. Nushell shows the warning when the line ends, after Enter or Ctrl+C.

Completion still works, because a compatibility bridge still gives context the old value. The warning says that a future Nushell release removes this bridge. After that, Tab completion for vp and vpr can stop working.

The warning gives the migration. Use [buffer, place]. $buffer replaces $context, and $place.cursor replaces its position.

This is the problem in the title of #3092. The body of #3092 describes a different problem, which #3123 fixes.

Reproduction

No repository is necessary. The steps use only vp and nu, and they write only to a temporary directory.

Steps to reproduce

The steps require vp, Nushell 0.116 or later, and fish. The completer calls fish.

  1. Generate env.nu in a temporary directory, so that no real shell profile changes.

     R=$(mktemp -d)
     HOME=$R/home ZDOTDIR=$R/home XDG_CONFIG_HOME=$R/config VP_HOME=$R/vp vp env setup --env-only
     grep -n 'def "nu-complete' "$R/vp/env.nu"
    
  2. Run the completer without a terminal.

     nu -n -c "source '$R/vp/env.nu'; 'vp en' | commandline complete --detailed | ignore"
    
  3. Or start a new interactive session in a terminal.

     nu -n -e "source '$R/vp/env.nu'"
    

    Type vp en and press Tab. The line becomes vp env. Then press Enter.

Expected result: Nushell shows no warning.

Actual result: Nushell shows nu::shell::deprecated. The Logs section has the full text. Nushell shows the warning only one time in a session.

This command shows the record that Nushell 0.116 gives to a completer.

nu -n -c "source '$R/vp/env.nu'; 'vp en' | commandline complete --input | to json -r"
# {"token":{"text":"en",...},"place":{"cursor":5,...,"command":["vp","en"]},"buffer":"vp en"}

System Info

vp v1.3.0
Nushell 0.116.1 (aarch64-apple-darwin)
fish 4.9.3
macOS

Used Package Manager

npm

Logs

Warning: nu::shell::deprecated

  ⚠ Positional completer input deprecated.
    ╭─[.../vp/env.nu:42:40]
 42 │ ╭─▶ def "nu-complete vp" [context: string] {
    ...
    · ╰──── declares the legacy positional input `context`
    ╰────
  help: A parameter completer is handed one record, whose fields bind to the parameters it names: token, place, buffer.
        `context` still receives its old positional value for compatibility, but this bridge will be removed in a future
        release. To migrate, use `[buffer, place]`; `$buffer` replaces the old context and `$place.cursor` replaces its
        position.

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Fields

Priority

None yet

Effort

None yet

Target date

None yet

Start date

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions