carapace-sh / carapace-bin

multi-shell multi-command argument completer
https://carapace.sh
MIT License
731 stars 43 forks source link

nix: flake output completion #2374

Open Atemu opened 3 weeks ago

Atemu commented 3 weeks ago

Request

2350 avoided adding these because fetching these was thought to be too slow (https://github.com/carapace-sh/carapace-bin/issues/2348).

This is however quite an essential feature using the nix CLI effectively.

cc @aftix

Proposed solution

Nix has built-in support for completions, couldn't those be leveraged?

NIX_GET_COMPLETIONS=2 nix build nixpkgs# instantly returns a list of completions.

Anything else?

No response

rsteube commented 3 weeks ago

Need to have a look at it, but should have the same issue. You probably get instant results because you have already invoked it before.

The problem is the first invocation. E.g. there is one nix command that triggers the channel download, which is like ~15mb as far as i remember. Anything above 100ms starts to feel slow in shell completion. Couple of seconds are fine when it is apparrent to the user that remote data needs to be fetched. But things like this simply block for quite a long time without any feedback. So it has to be a task detached from the shell completion. Nothing too complicated, but needs a generic concept as other commands have this issue as well.

Atemu commented 3 weeks ago

Indeed it has that issue. I pin my nixpkgs, so it is almost always cached for me.

It's honestly not that huge of an issue though IMHO. Better wait a few seconds every so often than to have no completion at all. It's the same with regular upstream bash completions, so, while obviously not ideal, this is intended behaviour.

aftix commented 3 weeks ago

With flakes, the time to generate the completions are much faster than using channels, but the first time running the completions command on a flake still takes ~2ish seconds to generate, even if used on a flake located in a local directory.