Skip to content

Tab-completion fails for commands with the same name from different modules #6765

Closed

Description

@anmenaga

Case 1: several modules each have a command with the same name (by coincidence)
Case 2: several top-level modules reference the same base module (e.g. having it as NestedModules with CmdletsToExport = '*')

In both cases tab-complete for such command fails and PS offers several instances of command with the same name which does not make sense from autocomplete point of view.
For example:

PS /home/pi> Test-TabCompl #press Tab here
Test-TabCompletion  Test-TabCompletion  Test-TabCompletion  Test-TabCompletion  

It looks like a new 'instance' in the list is getting added after according module is imported.
Also this list seems to be saved across PS sessions, so if at least 2 modules with the same command were ever imported - the tab-completion for the command will be broken forever.

Steps to reproduce

  1. Create several copies of the same module, rename the copies;
  2. Import each copy of the module;
  3. optionally, can exit PS here and start a new one;
  4. Try to tab-complete a command from the module.
PS /home/pi> Get-Module -ListAvailable


    Directory: /usr/local/share/powershell/Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
#...
Manifest   0.1.1      TestTabCompletion
Manifest   0.1.1      TestTabCompletion2
Manifest   0.1.1      TestTabCompletion3
Manifest   0.1.1      TestTabCompletion4
#...
PS /home/pi> ipmo TestTabCompletion
PS /home/pi> ipmo TestTabCompletion2
PS /home/pi> ipmo TestTabCompletion3
PS /home/pi> ipmo TestTabCompletion4
PS /home/pi> Test-TabComple # pressed Tab here
Test-TabCompletion  Test-TabCompletion  Test-TabCompletion  Test-TabCompletion
PS /home/pi> exit
pi@raspberrypi:~ $ sudo ./PS610P2/pwsh
PowerShell v6.1.0-preview.2
Copyright (c) Microsoft Corporation. All rights reserved.

PS /home/pi> Test-TabComple # pressed Tab here
Test-TabCompletion  Test-TabCompletion  Test-TabCompletion  Test-TabCompletion

Expected behavior

Tab-completion on the command should succeed.

Actual behavior

Tab-completion for command fails.

Environment data

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.2
PSEdition                      Core
GitCommitId                    v6.1.0-preview.2
OS                             Linux 4.9.41-v7+ #1023 SMP Tue Aug 8 16:00:15 BST 2017
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Bug
    WG-Engine
    on Apr 28, 2018
  2. SteveL-MSFT commented on Apr 29, 2018

    @SteveL-MSFT
    Member

    In the case where there are duplicates, we should see if we can provide the fully qualified cmdlet path with the module prefix

  3. lzybkr commented on Apr 29, 2018

    @lzybkr
    Contributor

    Try PSReadLine 2.0.0-beta1 - I think the experience is improved.

  4. Jaykul commented on Sep 15, 2023

    @Jaykul
    Contributor

    Fwiw, I think this is long fixed -- except that I would love to convert this issue into a request for the fix that Steve Lee (@SteveL-MSFT) proposed.

  5. added
    In-PR
    on Feb 19, 2024
  6. MartinGC94 commented on Feb 19, 2024

    @MartinGC94
    Contributor

    Joel Bennett (@Jaykul) It hasn't actually been fixed but PSReadLine added a workaround that deduplicates completion entries with the same list item text so it's not something users usually encounter. I've made a fix for this that does what Steve suggested.

  7. added
    Resolution-No Activity
    on Dec 16, 2024
  8. Jaykul commented on Dec 16, 2024

    @Jaykul
    Contributor

    It would be silly to close an issue with an open PR....

  9. removed
    Resolution-No Activity
    on Dec 16, 2024
  10. microsoft-github-policy-service commented on Mar 4, 2025

    @microsoft-github-policy-service
    Contributor

    📣 Hey Andrew (@anmenaga), how did we do? We would love to hear your feedback with the link below! 🗣️

    🔗 https://aka.ms/PSRepoFeedback

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIssue-BugWG-Engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions