KEMBAR78
MenuComplete filtering duplicates when it shouldn't be · Issue #3896 · PowerShell/PSReadLine · GitHub
Skip to content

MenuComplete filtering duplicates when it shouldn't be #3896

@thegraffix

Description

@thegraffix

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

N/A

Screenshot

Test files:
explorer


How the test function behaves (correctly) in ISE when using CTRL+SPACE:
ISE


How it behaves (correctly) in VSCode:
VSCode



How it behaves in the console (with PSReadLine). The duplicates have been eliminated when they shouldn't be; although the ListItemText is identical for the duplicate CompletionMatches, the objects represented by each CompletionResult are unique.
pwsh Console

Environment data

PS Version: 7.4.0
PS HostName: ConsoleHost
PSReadLine Version: 2.3.4
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 210
BufferHeight: 9000

Steps to reproduce

This is the test function I used.

Auto-complete (using either TAB or CTRL+SPACE) should only show files (and not folders) that start with "file" + a number between 2 and 9 (regardless of what comes after the number).

<# Get-ChildItem C:\test results:

file3.txt  <--- This is a directory
file1 - Copy.txt
file1.txt
file2 - Copy.txt
file2.txt
file4 - Copy.txt
file4.txt
[file].txt
#>

$gciParams = @{
    Path = Join-Path -Path 'C:\Test' -ChildPath '*'
    Filter = 'file*.*'
    File = $true
    Force = $true
}
<# (gci @gciParams).Name results:

file1 - Copy.txt
file1.txt
file2 - Copy.txt
file2.txt
file4 - Copy.txt
file4.txt
#>

$pattern = '.*[2-9].*'
$gciCommand = {Get-ChildItem @gciParams | Where-Object {$_.Name -match $pattern}}
<# (Invoke-Command $gciCommand).Name results:

file2 - Copy.txt
file2.txt
file4 - Copy.txt
file4.txt
#>

function Test-CompletionResult
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory, Position = 0, ParameterSetName = 'Num', ValueFromPipeline, ValueFromPipelineByPropertyName)]
        [ArgumentCompleter({
            param ($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
            $objList = @()
            (Invoke-Command -ScriptBlock $gciCommand).foreach({
                $filePath = $_.FullName
                $fileNum  = ($_.Name | Select-String -Pattern '\d').Matches.Value
                $objList += [pscustomobject] @{
                    Path = $filePath
                    Num  = $fileNum
                }
            })
            ($objList | Where-Object {$_.Num -like "*$WordToComplete*"}).foreach({
                [System.Management.Automation.CompletionResult]::new($_.Num, $_.Num, 'ProviderItem', $_.Path)
            })
        })]        
        [int]$FileNum
    )
    process {Write-Output $FileNum}
}

Expected behavior

  • MenuComplete items shouldn't be filtered out (or recognized as "duplicates") when the ListItemText is the same yet the CompletionResults are different for each MenuComplete item (as the CompletionResult tooltip(s) in my example illustrate)
  • Expected behavior should mirror how ISE and VSCode present CompletionResult items

Actual behavior

The "duplicate" MenuComplete items are filtered out.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions