Skip to content
New issue

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

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Commands for generating shell completion scripts + statically-generated bash script #42416

Open
wants to merge 63 commits into
base: main
Choose a base branch
from

Conversation

baronfel
Copy link
Member

@baronfel baronfel commented Jul 28, 2024

Part of #42397

Implements:

  • provider model for shell completions
  • new 'completions' command with 'script' and 'register' subcommands

Shell Support

shell recording static completions dynamic completions (e.g. nuget packages) slower, fallback completions
bash 🎥 ✔️ ✔️
zsh 🎥 ✔️ ✔️
pwsh 🎥 ✔️ ✔️
nushell ✔️
fish ✔️
  • for nushell/fish, the generate command just generates a correct-but-slow fallback wrapper
  • for bash, zsh, and powershell, comprehensive and very fast static completions have been implemented, even for dynamic completions like nuget packages
  • for zsh and powershell, descriptions of completion items are shown in nice menus

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Infrastructure untriaged Request triage from a team member labels Jul 28, 2024
@baronfel
Copy link
Member Author

baronfel commented Jul 28, 2024

I've implemented completion script generate for bash based partially on the excellent patterns that the Swift ArgumentParser library has used. Here's an example of the generated script (warning, 2100 lines of bash await you):

dotnet-bash-completions.txt

It works remarkably well - one of the harder parts was figuring out when truly dynamic completions were required and injecting a call to the dotnet CLI's completion command to generate suggestions for those cases. But where completions can be known statically we inject them. There is no good handling for file-based completions yet - one hurdle I faced was the very-pluggable completions model currently doesn't give any sense of attribution of the different completion sources - if I knew a given Func<CompletionContext, CompletionItem[]> was a certain kind of completion source I could maybe skip them for purposes of static script generation. As it is I had to create my own signal for that kind of data.

@baronfel baronfel changed the title Completions registration Commands for generating shell completion scripts + statically-generated bash script Jul 28, 2024
@baronfel baronfel force-pushed the completions-registration branch from 4fa8920 to 6f266e8 Compare July 28, 2024 15:15
@baronfel baronfel added Area-CLI cli-ux Issues and PRs that deal with the UX of the CLI (exit codes, log output, verbs/options, and so on) labels Jul 28, 2024
@baronfel baronfel force-pushed the completions-registration branch from 64269f3 to af2fa73 Compare July 31, 2024 21:35
@baronfel baronfel marked this pull request as ready for review December 30, 2024 22:52
@baronfel baronfel requested review from a team as code owners December 30, 2024 22:52
@baronfel
Copy link
Member Author

Ok, I've updated the description. This is now ready for a review + discussion.

I've done almost all of the work in a separate library project - this is something that we should consider spinning off in the future, as the only real dependency it has is System.CommandLine. If that becomes stable then it'd be fitting for a library.

Assuming the library is implemented (and there are some baseline tests added) then the usage of the library in the dotnet CLI becomes very simple.

@baronfel baronfel requested a review from a team December 30, 2024 23:07
Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

I didn't look at shell-specific code or test code, but this looks great! I appreciated the videos in the description, but you might need to work on your typing speed (or crop the first half of the video) 😉

@Evangelink
Copy link
Member

@baronfel I'm guessing this can only work when the options are statically registered and so it won't work for our new dotnet test experience, right?

baronfel and others added 28 commits March 1, 2025 12:43
If we have corrected paths from the extension methods, maybe we don't need this override?
By not copying the snapshots to build output, and by making Verify
condition the checks for where to look for the snapshots, we can keep
a good dev experience of diffs on in-tree files instead of digging in
build output directories. CI test failures will still be unfortunately messy.
Co-authored-by: Michael Yanni <MiYanni@microsoft.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Area-CLI Area-Infrastructure cli-ux Issues and PRs that deal with the UX of the CLI (exit codes, log output, verbs/options, and so on) untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants