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

Merged
merged 4 commits into from
Dec 10, 2024

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
  • pipeline
    • Import module Pester for e2e tests
  • 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 Test

  • Azure pipeline for vcpkg

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

@WangWeiLin-MV WangWeiLin-MV force-pushed the scripts/posh-vcpkg branch 10 times, most recently from 686cb63 to c56f17d Compare November 14, 2024 05:19
@WangWeiLin-MV WangWeiLin-MV force-pushed the scripts/posh-vcpkg branch 2 times, most recently from 3eb6c32 to 4140534 Compare November 20, 2024 03:20
@WangWeiLin-MV WangWeiLin-MV marked this pull request as ready for review November 27, 2024 05:52
@@ -101,9 +103,10 @@ try {
Set-Content -Path "out/scripts/buildsystems/msbuild/vcpkg.props" -Value $propsContent -NoNewline -Encoding Ascii

Copy-Item -Path "$PSScriptRoot/vcpkg.targets" -Destination 'out/scripts/buildsystems/msbuild/vcpkg.targets'
New-Item -Path 'out/scripts/posh-vcpkg/0.0.1' -ItemType 'Directory' -Force
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No comments fund about the version-directory.

If the original intention is to load the latest version:

  • For users, the higher version overwrites the lower version
  • For developers, the command Get-Module -ListAvailable -Refresh is required when refreshing the module cache.

So, removing it to avoid changing this script again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Requires test for Azure pipeline of vcpkg.

& $matches['vcpkgexe'] autocomplete $matches['remaining']
return
}
[PowerShell]$cmd = [PowerShell]::Create().AddScript{
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

Comment on lines +8 to +10
if ($cursorPosition -lt $commandAst.CommandElements[0].Extent.EndOffset) {
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.

e.g. & ^ vcpkg ver

Return no output to fall back to default file name completion.

'TabExpansion'
)
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.

e.g. vcpkg install versions^ (No port named versions but directory .\versions\)

Unable to prevent fallback to default completion.

(Unless get an error, like return empty string.)

It will fallback default with:

  • return
  • return $null
  • return @()
  • return [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new()

See PowerShell/PowerShell#19628

@WangWeiLin-MV WangWeiLin-MV marked this pull request as draft November 27, 2024 06:14
@WangWeiLin-MV WangWeiLin-MV marked this pull request as ready for review December 9, 2024 02:27
@BillyONeal BillyONeal merged commit 074906a into microsoft:main Dec 10, 2024
6 checks passed
@BillyONeal
Copy link
Member

Thanks for the improvement!

@WangWeiLin-MV WangWeiLin-MV deleted the scripts/posh-vcpkg branch December 11, 2024 02:13
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.

2 participants