Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul completions, redo #6693 #8131

Merged
merged 1 commit into from Oct 23, 2023

Conversation

Ericson2314
Copy link
Member

Motivation

As I complained in
#6784 (comment) (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.

Context

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).

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or incompatible change: updated release notes

Priorities

Add 馃憤 to pull requests you find important.

@ncfavier
Copy link
Member

Regressions:

$ nix flake show ~/flake --update-input <Tab>
(no output)
$ nix run ~/flake --update-input <Tab>
(no output)

Basically we only get tilde expansion for InstallablesCommands now (note the s). I think the whole reason I made getFlakesForCompletion return a string was so that the completion code could take care of tilde expansion instead of doing it in every class.

@Ericson2314
Copy link
Member Author

@ncfavier Thanks. Let's try to get those in the test prior to merging this PR I think.

Basically we only get tilde expansion for InstallablesCommand now (note the s).

Thanks, that should be an easy enough fix.

I think the whole reason I made getFlakesForCompletion return a string was so that the completion code could take care of tilde expansion instead of doing it in every class.

Oh hmm I didn't think it looked that way, but I'll think about this.

@Ericson2314 Ericson2314 marked this pull request as draft March 31, 2023 11:18
@fricklerhandwerk fricklerhandwerk added new-cli Relating to the "nix" command flakes labels Mar 31, 2023
@thufschmitt thufschmitt self-assigned this Mar 31, 2023
@Ericson2314 Ericson2314 mentioned this pull request Apr 2, 2023
10 tasks
@Ericson2314 Ericson2314 marked this pull request as ready for review April 3, 2023 03:42
@github-actions github-actions bot added with-tests Issues related to testing. PRs with tests have some priority and removed documentation labels Apr 3, 2023
@Ericson2314
Copy link
Member Author

@ncfavier Hmm I am confused. I added tests based on what you said, but I didn't see any regressions.

tests/completions.sh Outdated Show resolved Hide resolved
@Ericson2314 Ericson2314 marked this pull request as draft April 3, 2023 12:06
@Ericson2314
Copy link
Member Author

Ericson2314 commented Apr 3, 2023

OK, now it is fixed :). Thanks again, @ncfavier, those tests proved quiete helpful in catching both places that needed to change.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-03-31-nix-team-meeting-minutes-45/27002/1

Copy link
Contributor

@fricklerhandwerk fricklerhandwerk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed with @tomberek.

Overall the change is good, but it needs a bit of clarification for us mortals who don't dream in C++ (yet).

Would be great to have the new docstrings as a separate commit for easier bisection.

src/libutil/args/root.hh Outdated Show resolved Hide resolved
src/libutil/args.hh Show resolved Hide resolved
src/libutil/args.hh Show resolved Hide resolved
src/libutil/args.hh Show resolved Hide resolved
src/libutil/args.hh Outdated Show resolved Hide resolved
As I complained in
NixOS#6784 (comment) (a
comment on the wrong PR, sorry again!), NixOS#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 NixOS#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>
@github-actions github-actions bot removed the with-tests Issues related to testing. PRs with tests have some priority label Oct 16, 2023
@fricklerhandwerk
Copy link
Contributor

I'd need to review it again in full as it seems to have changed quite a bit, and I'm not sure I'll find enough time for it in the next week given other priorities. But my clarification requests were addressed in code comments, so I'm almost at peace with this change. @tomberek could you take it over the finish line?

@Ericson2314
Copy link
Member Author

Sounds good

seems to have changed quite a bit

I don't think I changed it a lot? Mean thing is I landed the tests and API docs for existing stuff first. The rest should be more or less the same (just small things in response to review comments). At least I don't remember doing anything big!

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-10-16-nix-team-meeting-minutes-95/34396/1

Copy link
Contributor

@fricklerhandwerk fricklerhandwerk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, now that I got the quiet to look at it properly, this looks very good. The doc comments help a lot with following the code, and the updated names don't stick out any more.

@fricklerhandwerk fricklerhandwerk merged commit b461cac into NixOS:master Oct 23, 2023
8 checks passed
@Ericson2314 Ericson2314 deleted the overhaul-completions branch October 23, 2023 13:15
roberth added a commit to hercules-ci/nix that referenced this pull request Oct 23, 2023
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-10-23-nix-team-meeting-minutes-97/34561/1

roberth added a commit to hercules-ci/nix that referenced this pull request Nov 6, 2023
roberth added a commit to hercules-ci/nix that referenced this pull request Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flakes new-cli Relating to the "nix" command RFC Related to an accepted RFC
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants