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

[scripts/posh-vcpkg] Change TabExpansion to Register-ArgumentCompleter #1512

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

WangWeiLin-MV
Copy link
Contributor

@WangWeiLin-MV WangWeiLin-MV commented Oct 16, 2024

Fixes for microsoft/vcpkg#38184

The function TabExpansion is not supported by PowerShell 7.4.0, which breaks the posh-vcpkg.psm1 for vcpkg integrate powershell.

Use Register-ArgumentCompleter instead of TabExpansion to fix it.

Change

  • vcpkg-init
    • Move posh-vcpkg module to non-version directory
  • posh-vcpkg
    • Update posh-vcpkg.psd1 minimum version from 5.0 to 5.1
    • Replace intercepting TabExpansion with Register-ArgumentCompleter
  • e2e
    • Add end-to-end-tests-dir/autocomplete-posh-vcpkg.ps1
    • Add e2e-specs/autocomplete-posh-vcpkg.Tests.ps1

Test

Test passes locally on

  • PowerShell 7.4.2 with Pester 5.6.1 on Linux
  • PowerShell 7.4.3 with Pester 5.6.1 on macOS
  • PowerShell 7.4.6 with Pester 5.6.1 on Windows
  • Windows PowerShell 5.1 with Pester 5.6.1 on Windows
    • PowerShell ignore minus(-) string before Core PowerShell/issues/2912

@WangWeiLin-MV WangWeiLin-MV marked this pull request as draft October 16, 2024 11:12
@WangWeiLin-MV
Copy link
Contributor Author

WangWeiLin-MV commented Oct 16, 2024

Waiting PR

Test case passed

  • autocomplete-posh-vcpkg.ps1
  • autocomplete-posh-vcpkg.Tests.ps1

The symbol ^ represents the cursor.

  • vcpkg ver^ got version
  • vcpkg version^ got version
  • vcpkg ^version got command list
  • vcpkg ^ got command list
  • ./vcpkg ^ got command list
  • vcpkg.exe ^ got command list only on Windows
  • .\vcpkg ^ got command list only on Windows
  • vcpkg install vcpkg-cmake:^ got triplet list
  • vcpkg install vcpkg-cmake -^ got command list
  • echo powershell | % { vcpkg int^egr $_ }; echo $? got integrate
  • vcpkg zzzzzzzz^ got empty completion
  • vcpkg ---^ got empty completion
  • vcpkg --triplet^ won't get error

Comment on lines 28 to 37
[PowerShell]$cmd = [PowerShell]::Create().AddCommand($commandText).AddParameters(
@('autocomplete') + $textsBeforeCursor + $spaceToComplete
)
}

Export-ModuleMember @exportModuleMemberParams
[string[]]$completions = $cmd.Invoke()

if ($cmd.HadErrors -or $completions.Count -eq 0) {
return @()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prevent vcpkg errors passing to user shell

vcpkg autocomplete install --triplet
error: the option 'triplet' requires a value

@WangWeiLin-MV WangWeiLin-MV force-pushed the scripts/posh-vcpkg branch 3 times, most recently from e14a7c2 to fb13f71 Compare November 8, 2024 10:31
@WangWeiLin-MV WangWeiLin-MV force-pushed the scripts/posh-vcpkg branch 11 times, most recently from 686cb63 to c56f17d Compare November 14, 2024 05:19
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.

1 participant