Add dynamic tab completions for command arguments via System.CommandLine CompletionSources - #15
Merged
Merged
Conversation
…ine CompletionSources Add CompletionSources to command arguments so that dotnet-suggest can provide dynamic tab completions from the xrepo registry: - ref: suggests registered repo names and package IDs - which/where: suggests registered package IDs - repo unregister: suggests registered repo names - unref: suggests registered repo names https://claude.ai/code/session_01QqNiEkuZb4LPkFdZ8sV1rC
System.CommandLine automatically provides file path completions when an option is typed as FileInfo instead of string. https://claude.ai/code/session_01QqNiEkuZb4LPkFdZ8sV1rC
The ref command accepts repo names, package IDs, or .csproj file paths, but tab completion only suggested repos and packages. Now it also enumerates .csproj files from the current directory tree. https://claude.ai/code/session_01QqNiEkuZb4LPkFdZ8sV1rC
Instead of pre-enumerating all .csproj files recursively, use WordToComplete from the completion context to provide path-based completions. This shows subdirectories and .csproj files matching what the user has typed so far, allowing navigation to any .csproj on the file system. https://claude.ai/code/session_01QqNiEkuZb4LPkFdZ8sV1rC
Move the file path completion logic from RefCommand into a shared FileCompletions.Get() helper that accepts file extensions. Add solution file (.sln/.slnx) completion to the --solution option on both RefCommand and UnrefCommand. https://claude.ai/code/session_01QqNiEkuZb4LPkFdZ8sV1rC
Tests cover: empty input, directory prefix navigation, partial filename filtering, partial directory name filtering, nonexistent directory, multiple extensions, case insensitivity, and trailing separator on directory completions. https://claude.ai/code/session_01QqNiEkuZb4LPkFdZ8sV1rC
Owner
Author
Code reviewFound 1 issue:
xrepo/src/CommandLine/Commands/Unref.cs Lines 15 to 51 in efcdadc 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
…t reference removal and improve maintainability. Added tests for `ResolveProjects` behavior.
System.CommandLine 2.0.3 renders CompletionSources values as the argument placeholder in --help output. Setting HelpName on each Argument and Option that has dynamic completions tells the help builder to display a clean label instead.
…updated `Ref` and `Unref` commands to use the new logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CompletionSourcesto command arguments sodotnet-suggestprovides tab completions from the xrepo registry:ref: registered repo names, package IDs, and file path completions for .csproj fileswhich/where: registered package IDsrepo unregister: registered repo namesunref: registered repo names and package IDs--solutionoption type fromstringtoFileInfoso System.CommandLine provides built-in file path tab completiondotnet-suggest script zshoutputunrefcommand: Thenameargument was documented but being ignored —xrepo unrefalways removed all references regardless of whether a name was specified. Nowxrepo unref <name>selectively removes only the project references associated with the given repo or package, whilexrepo unref(with no argument) continues to remove everything.How it works
System.CommandLine 2.0's
RootCommandalready includes the[suggest]directive, so xrepo supports thedotnet-suggestcompletion protocol out of the box. TheCompletionSources.Add()calls provide dynamic values from the xrepo registry, andOption<FileInfo?>triggers native file path completion in the shell.Selective unref
UnrefCommandnow reads the optionalnameargument and dispatches to either:UnrefAll(no argument): removes allXRepoReferenceItemGroups from every consuming project, removes thexreposolution folder, and runsdotnet restore.UnrefByName(repo name or package ID): resolves the name to specific project paths, removes only those project references, and only removes thexreposolution folder if no xrepo references remain anywhere.New methods added to
ConsumingProject:RemoveXRepoProjectReference(string projectPath)— removes a specific reference, cleans up empty ItemGroupsHasXRepoProjectReferences()— checks if any XRepoReference ItemGroups remainTest plan
dotnet test) — 60 unit tests + 1 scenario test[suggest]directive returns subcommands[suggest]returns options for specific commandsRemoveXRepoProjectReferenceandHasXRepoProjectReferences🤖 Generated with Claude Code