nushell / nushell

A new type of shell
https://www.nushell.sh/
MIT License
32.15k stars 1.66k forks source link

Cargo completion freezes the terminal when there is more than one target #5045

Closed Hofer-Julian closed 1 year ago

Hofer-Julian commented 2 years ago

Problem:

If I use cargo-completions it freezes the terminal when I have one than more possibility.

Steps to reproduce

(The same thing happens with cargo run --example)

Note

It is not obvious to me why that happens, it seems to do the same thing as the git completion which works fine. I've only tested this on Windows.

fdncred commented 2 years ago

tried to repro and it totally hung my windows terminal - no clue what's going on here but i have an idea of something to check. since cargo run --bin <tab> calls the "nu-complete cargo bins" command what happens if you call it directly? (you have to change it from a module to a regular script to call these directly)

Oh! I think i see what is going on. If you look at this command.

def "nu-complete cargo bins" [] { nu-complete cargo targets bin }

it's calling another completer

def "nu-complete cargo targets" [type: string] {
  cargo metadata --format-version=1 --offline --no-deps | from json | get packages.targets | flatten | where ($type in $it.kind) | get name
}

is that legal? also, should nu-complete cargo targets be in quotes when calling it?

fdncred commented 2 years ago

the completers appear to work when called directly. i'm transferring to nushell. i'm thinking there may be a bug there.

fdncred commented 2 years ago

i changed the cargo completions so i could run the completers normally.

> cd .\ripgrep\
> nu-complete cargo bins 
╭───┬────╮
│ 0 │ rg │
╰───┴────╯
> nu-complete cargo examples 
╭───┬──────────────╮
│ 0 │ simplegrep   │
│ 1 │ search-stdin │
│ 2 │ walk         │
╰───┴──────────────╯
> cargo run --bin <tab>

the last command just hangs and i'm not sure why. is it a bug in the completion script or a bug in how nushell is trying to complete. It's not clear since there is no error message and it just hangs.

fdncred commented 2 years ago

more research. it seems that this command is hanging "C:\\Users\\username\\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe" metadata --format-version=1 --offline --no-deps i can kill that subprocess and the hanging part ends.

  1. i wonder if our double backslash bug is breaking it - i can't run that command at all just as it sits. i have to remove the quotes altogether to get nushell to like it.
  2. i wonder if cargo is hanging by itself - i tried to run the command and it returns a json string without issue.
  3. or perhaps our double quote escaping is causing something weird?
sophiajt commented 1 year ago

Closing this, as we don't ship with cargo completions anymore. If there are bugs on the cargo completions, we should probably file them on nu_scripts (if they still repro) or if we think it's a nushell related issue, then to reduce the repro and file a new issue here.