Skip to content

Conversation

@nagilson
Copy link
Member

I confirmed the proposal by Kalle, which resolves #48420 and confirmed that the shellMap that gets provided is a default list of shell names like "fish" or "zsh" that are stored in the Shell Env Var. They are all lowercase in the shell map.

I confirmed the proposal by Kalle, dotnet#48420 that the shellMap that gets provided is a default list of shell names like "fish" or "zsh" that are stored in the Shell Env Var. They are all lowercase in the shell map.
Copilot AI review requested due to automatic review settings May 13, 2025 18:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR aims to enable static completions to work in scenarios where a shell has not been specified on Unix by leveraging a default mapping of lowercase shell names. Key changes include:

  • Adding a test (ShellDiscoveryTests.cs) to validate that the completions command works without an explicit shell.
  • Updating CompletionsCommand.cs to convert the shell name to lowercase before lookup in the shell map.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/dotnet.Tests/CompletionTests/ShellDiscoveryTests.cs Adds a new test ensuring completions work even without a specified shell.
src/System.CommandLine.StaticCompletions/CompletionsCommand.cs Normalizes the shell name to lowercase to match against the shell map.


public class ShellDiscoveryTests()
{
[Fact]
Copy link
Member

Choose a reason for hiding this comment

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

maybe parameterize this test with the shell names and set the SHELL env var before each run so we can easily test all of our shell experiences??

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a great point -- I think this test should be ok since it works in general on any generic shell. If we had more capacity I would probably add this to the test, but not going to prioritize it right now. Thank you for reviewing

@nagilson nagilson requested a review from Copilot October 3, 2025 18:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.



using System.CommandLine.StaticCompletions.Shells;
using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown;
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The using statement for Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown appears unused in this test class. Unused using directives should be removed.

Suggested change
using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown;

Copilot uses AI. Check for mistakes.

using System.CommandLine.StaticCompletions.Shells;
using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown;
using Microsoft.Extensions.Options;
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The using statement for Microsoft.Extensions.Options appears unused in this test class. Unused using directives should be removed.

Suggested change
using Microsoft.Extensions.Options;

Copilot uses AI. Check for mistakes.
@nagilson
Copy link
Member Author

nagilson commented Oct 3, 2025

@copilot The new test used to work but now fails with: System.ArgumentException : No symbol result found with name "@CompletionsCommand_ShellArgument_Description". What changed in the codebase between then and now that makes the test invalid and can you fix it?

Comment on lines -70 to +71
var shellName = Path.GetFileName(shellPath);
if (shellMap.TryGetValue(shellPath, out var shellProvider))
var shellName = Path.GetFileName(shellPath).ToLower();
if (shellMap.TryGetValue(shellName, out var shellProvider))
Copy link
Contributor

Choose a reason for hiding this comment

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

The .ToLower() call should not be necessary, because shellMap is using StringComparer.OrdinalIgnoreCase:

public CompletionsCommand(IEnumerable<IShellProvider>? supportedShells = null, string commandName = "completions", string? commandDescription = null) : this((supportedShells ?? DefaultShells).ToDictionary(s => s.ArgumentName, StringComparer.OrdinalIgnoreCase), commandName, commandDescription ?? Strings.CompletionsCommand_Description)

… unless you specifically want culture-specific case folding here, e.g. FISH to fısh in a Turkish culture. But that seems more likely to hurt than help because none of the known shell names includes a dotless ı.

{
ParseResult result = Parser.Parse(["dotnet", "completions", "script"]);
result.Errors.Should().BeEmpty();
result.GetValue<IShellProvider>("@CompletionsCommand_ShellArgument_Description").Should().NotBeNull();
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this at-sign syntax "@CompletionsCommand_ShellArgument_Description"? Shouldn't the argument be simply "shell", matching the Argument<IShellProvider> construction here:

var shellArg = new Argument<IShellProvider>("shell")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotnet completions script produces confusing error when no shell supplied

3 participants