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

Fix tab-completion regression caused by switch to Register-ArgumentCompleter #741

Merged
merged 2 commits into from
Feb 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Enable tab expansion logging
  • Loading branch information
rkeithhill committed Feb 21, 2020
commit fb14c901857cdca55cea105973a1997d87f8c8cc
15 changes: 13 additions & 2 deletions src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Initial implementation by Jeremy Skinner
# http://www.jeremyskinner.co.uk/2010/03/07/using-git-with-windows-powershell/

$tabLogPath = Join-Path ([System.IO.Path]::GetTempPath()) posh-git_tabexp.log

$Global:GitTabSettings = New-Object PSObject -Property @{
AllCommands = $false
KnownAliases = @{
Expand Down Expand Up @@ -470,10 +472,13 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) {
}
}

if ($PSVersionTable.PSVersion.Major -ge 6) {
if (!$env:PoshGitUseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) {
Microsoft.PowerShell.Core\Register-ArgumentCompleter -CommandName git,tgit,gitk -Native -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)

$trimToLength = $cursorPosition - $commandAst.Extent.StartOffset
$alt = $commandAst.toString().PadRight($trimToLength, ' ').substring(0, $trimToLength)
"[$(Get-Date -Format HH:mm:ss)] New tab exp: '$($commandAst.Extent.Text)' - alt: '$alt'" | Out-File -Append $tabLogPath
Expand-GitCommand $commandAst.Extent.Text
}
}
Expand All @@ -492,12 +497,16 @@ else {
}

if (Test-Path Function:\TabExpansion) {
"[$(Get-Date -Format HH:mm:ss)] Old tab exp: backing up TabExpansion2 to TabExpansionBackup" | Out-File -Append $tabLogPath
Rename-Item Function:\TabExpansion TabExpansionBackup
"[$(Get-Date -Format HH:mm:ss)] Old tab exp: dir $(Get-ChildItem function:\Tab* | % Name)" | Out-File -Append $tabLogPath
}

function TabExpansion($line, $lastWord) {
$lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart()

"[$(Get-Date -Format HH:mm:ss)] Old tab exp: '$lastBlock'" | Out-File -Append $tabLogPath

switch -regex ($lastBlock) {
# Execute git tab completion for all git-related commands
"^$(Get-AliasPattern git) (.*)" { Expand-GitCommand $lastBlock }
Expand All @@ -506,8 +515,10 @@ else {

# Fall back on existing tab expansion
default {
"[$(Get-Date -Format HH:mm:ss)] Old tab exp: fallback to default case" | Out-File -Append $tabLogPath
if (Test-Path Function:\TabExpansionBackup) {
TabExpansionBackup $line $lastWord
"[$(Get-Date -Format HH:mm:ss)] Old tab exp: line: '$line' lastWord: '$lastWord'" | Out-File -Append $tabLogPath
TabExpansionBackup -InputScript $line $lastWord
}
}
}
Expand Down