lix-releng-staging/src
John Ericson 3d065192c0 Overhaul completions, redo #6693 (#8131)
As I complained in
https://github.com/NixOS/nix/pull/6784#issuecomment-1421777030 (a
comment on the wrong PR, sorry again!), #6693 introduced a second
completions mechanism to fix a bug. Having two completion mechanisms
isn't so nice.

As @thufschmitt also pointed out, it was a bummer to go from `FlakeRef`
to `std::string` when collecting flake refs. Now it is `FlakeRefs`
again.

The underlying issue that sought to work around was that completion of
arguments not at the end can still benefit from the information from
latter arguments.

To fix this better, we rip out that change and simply defer all
completion processing until after all the (regular, already-complete)
arguments have been passed.

In addition, I noticed the original completion logic used some global
variables. I do not like global variables, because even if they save
lines of code, they also obfuscate the architecture of the code.

I got rid of them  moved them to a new `RootArgs` class, which now has
`parseCmdline` instead of `Args`. The idea is that we have many argument
parsers from subcommands and what-not, but only one root args that owns
the other per actual parsing invocation. The state that was global is
now part of the root args instead.

This did, admittedly, add a bunch of new code. And I do feel bad about
that. So I went and added a lot of API docs to try to at least make the
current state of things clear to the next person.

--

This is needed for RFC 134 (tracking issue #7868). It was very hard to
modularize `Installable` parsing when there were two completion
arguments. I wouldn't go as far as to say it is *easy* now, but at least
it is less hard (and the completions test finally passed).

Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Change-Id: If18cd5be78da4a70635e3fdcac6326dbfeea71a5
(cherry picked from commit 67eb37c1d0de28160cd25376e51d1ec1b1c8305b)
2024-03-25 15:30:36 +00:00
..
build-remote libutil: make AutoCloseFD a better resource 2024-03-18 15:42:52 -06:00
libcmd Overhaul completions, redo #6693 (#8131) 2024-03-25 15:30:36 +00:00
libexpr build: optionally build and install with meson 2024-03-22 08:36:50 -06:00
libfetchers build: optionally build and install with meson 2024-03-22 08:36:50 -06:00
libmain Overhaul completions, redo #6693 (#8131) 2024-03-25 15:30:36 +00:00
libstore libstore: despecialcase protocol version check 2024-03-24 18:45:22 +00:00
libutil Overhaul completions, redo #6693 (#8131) 2024-03-25 15:30:36 +00:00
nix Overhaul completions, redo #6693 (#8131) 2024-03-25 15:30:36 +00:00
nix-build Delete hasPrefix and hasSuffix from the codebase 2024-03-17 20:17:19 -07:00
nix-channel libutil: make AutoCloseFD a better resource 2024-03-18 15:42:52 -06:00
nix-collect-garbage util.hh: split out signals stuff 2024-03-11 00:52:09 -07:00
nix-copy-closure Merge pull request #9277 from keszybz/file-permissions 2024-03-04 05:26:17 +01:00
nix-env Delete hasPrefix and hasSuffix from the codebase 2024-03-17 20:17:19 -07:00
nix-instantiate Unify and refactor value printing 2024-03-09 03:50:06 +01:00
nix-store libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
resolve-system-dependencies libutil: make AutoCloseFD a better resource 2024-03-18 15:42:52 -06:00
toml11 build: optionally build and install with meson 2024-03-22 08:36:50 -06:00
meson.build build: optionally build and install with meson 2024-03-22 08:36:50 -06:00