Skip to content

Conversation

@Hasan-8326
Copy link

This PR updates pip's PowerShell autocompletion logic to support modern PowerShell versions (7.4 and newer, including PowerShell Core 6+). Previously, pip relied on the legacy Tab Expansion function, which no longer exists in these versions, causing autocompletion to break.

Changes

  • Detect if Register-Argument Completer is available in the current PowerShell environment.
  • Use Register-Argument Completer to provide tab completion for the pip command in supported PowerShell versions.
  • Retain fallback to the legacy TabExpansion for older PowerShell versions.
  • The new implementation correctly sets $Env:COMP_WORDS, $Env:COMP_CWORD, and $Env:PIP_AUTO_COMPLETE for argument completion.

How to Test

  1. Open PowerShell 7.4+ (or PowerShell Core 7.x).
  2. Run:
    Invoke-Expression (pip completion --powershell)

@sepehr-rs
Copy link
Member

Hi @Hasan-8326, thank you for taking the time to contribute to pip!
I took a look at your PR, and there are a few things that need to be addressed before it can move forward:

  1. According to pip's contribution guidelines, your PR needs a news file. You can read more about it here. Please let me know if you need any help in adding one.
  2. It looks like the changes are currently in the wrong location. The autocompletion scripts live in pip/src/pip/_internal/commands/completion.py, so you should move your code there.
  3. Finally, this PR is a duplicate of Fix: Fix PowerShell completion test for Register-ArgumentCompleter #13577, which maintainers decided not to merge due to issues discussed in Completions registered with pip completion don't work when pip is invoked differently #13593.

Thanks again for contributing. We really value your interest in improving pip!

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.

3 participants