Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuComplete filtering duplicates when it shouldn't be #3896

Closed
3 tasks done
thegraffix opened this issue Dec 11, 2023 · 2 comments · Fixed by #3897
Closed
3 tasks done

MenuComplete filtering duplicates when it shouldn't be #3896

thegraffix opened this issue Dec 11, 2023 · 2 comments · Fixed by #3897

Comments

@thegraffix
Copy link

thegraffix commented Dec 11, 2023

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.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Dec 11, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR A PR is opened targeting the issue label Dec 11, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Dec 11, 2023
@daxian-dbw daxian-dbw added Resolution-Fixed and removed In-PR A PR is opened targeting the issue labels Dec 11, 2023
@thegraffix
Copy link
Author

It appears this issue still persists in PSReadLine 2.3.5

Should I create a new issue or does it make more sense to re-open this one?


2024-05-17 14 30 06

@daxian-dbw
Copy link
Member

The fix was included in the v2.4.0-beta0 release, not in v2.3.5, which is a v2.3 servicing release. Please upgrade to v2.4.0-beta0 and give it a try.

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

Successfully merging a pull request may close this issue.

2 participants