Skip to content

fix: pwsh autocompletion not returning command hints#1685

Draft
nrynmish wants to merge 3 commits intofastapi:masterfrom
nrynmish:fix/pwsh-autocompletion-266
Draft

fix: pwsh autocompletion not returning command hints#1685
nrynmish wants to merge 3 commits intofastapi:masterfrom
nrynmish:fix/pwsh-autocompletion-266

Conversation

@nrynmish
Copy link
Copy Markdown

Closes #266

What's the bug?

PowerShellComplete.get_completion_args() was slicing cwords[1:] to skip the interpreter, but $commandAst.ToString() in the PowerShell template includes both the interpreter (python) and the prog name (main.py) as the first two tokens.

This meant main.py was leaking into the args passed to Click's completion resolver, which couldn't match it to any command and returned no completions — causing PowerShell to silently fall back to path-only completion.

Changes

typer/_completion_classes.py

  • Changed cwords[1:]cwords[2:] and cwords[1:-1]cwords[2:-1] in PowerShellComplete.get_completion_args() to correctly skip both the interpreter and prog name tokens.

typer/_completion_shared.py

  • Replaced $Env:VAR = "" with Remove-Item Env:VAR to fully unset environment variables after completion, preventing stale values from affecting repeated completions.

Testing

Tested by mocking _TYPER_COMPLETE_ARGS and _TYPER_COMPLETE_WORD_TO_COMPLETE env vars and asserting correct args slicing before and after the fix. Also verified end-to-end with pwsh on Linux.

Copy link
Copy Markdown
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I'll put this in draft while the test suite fails, feel free to mark as ready when everything is green.

@svlandeg svlandeg marked this pull request as draft April 13, 2026 07:49
@svlandeg svlandeg added the bug Something isn't working label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Auto-completion not work in pwsh

3 participants