Skip to content

Commit

Permalink
Fix completions
Browse files Browse the repository at this point in the history
  • Loading branch information
codyduong committed Apr 20, 2024
1 parent 410fdc8 commit ae8093a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions windows/components/completions.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Get-ChildItem -Path (Join-Path $PSScriptRoot "completions")
| Where-Object { $_.extension -eq ".ps1" }
| Where-Object { $_.Name[0] -ne "." }
# | Where-Object { $_.Name -notlike 'komorebic.ps1*'}
| ForEach-Object -process {
# Invoke-Expression ". '$_'"
Write-Host "components.$_ : $(Measure-Command { Invoke-Expression ". '$_'" })"

Check warning

Code scanning / PSScriptAnalyzer

Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead. Warning

Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead.

Check warning

Code scanning / PSScriptAnalyzer

File 'completions.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information. Warning

File 'completions.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information.
Expand Down
8 changes: 4 additions & 4 deletions windows/components/completions/komorebic.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
. $PSScriptRoot/.TrimFzfTrigger.ps1

$script:completions_komorebic_export_version = [semver]'0.1.0'
$script:completions_komorebic_version = $($(komorebic --version | Out-String) -replace 'komorebic','').Trim()
$script:completions_komorebic_version = $($(komorebic --version) -replace 'komorebic','').Trim()

function Export-CompletionsKomorebicClixml {
Param(
Expand Down Expand Up @@ -146,9 +146,9 @@ function Register-CompletionsKomorebic {
[semver]$clixml_export_version = if ($null -ne $clixml.export_version) { [semver]($clixml.export_version) } else { [semver]'0.0.0' }
[semver]$clixml_komorebic_version = if ($null -ne $clixml.komorebic_version) { [semver]($clixml.komorebic_version) } else { [semver]'0.0.0' }
if (
$clixml_export_version -lt $script:export_version -or
$clixml_komorebic_version -ne $script:komorebic_version) {
Write-Host "$clixml_export_version, $script:export_version, $clixml_komorebic_version, $script:komorebic_version"
$clixml_export_version -lt $script:completions_komorebic_export_version -or
$clixml_komorebic_version -ne $script:completions_komorebic_version) {
# Write-Host "$clixml_export_version, $script:export_version, $clixml_komorebic_version, $script:komorebic_version"
$clixml = Export-CompletionsKomorebicClixml -PassThru
}

Expand Down
26 changes: 20 additions & 6 deletions windows/components/completions/yarn.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
. $PSScriptRoot/.completions.ps1
# Ironically we use npm Get-NpmRun for our Yarn Run completions... it's just easier...
. $PSScriptRoot/npm.ps1
# . $PSScriptRoot/npm.ps1

$script:completions_yarn_export_version = [semver]'0.1.0'
$script:completions_yarn_version = $(yarn --version).Trim()
Expand Down Expand Up @@ -353,6 +353,7 @@ function Get-CompletionsYarn {
$currently_at = $yarn
# values evaluated at runtime rather than beforehand
$evaluated = @()
$runCompletions = @()

# get as far as possible in autocomplete tree
foreach ($part in $parts) {
Expand All @@ -366,13 +367,19 @@ function Get-CompletionsYarn {
$currently_at = $next
}

# Read through all <.*> values, and parse them according to our helpers
foreach ($possible in $currently_at.Keys) {
if ($possible -match "<command>") {
$evaluated += & $GetNpmRunRef
}
# if we are at the base level or at run then we can use run completions
if ($parts.Length -eq 1 -or $last -eq 'run' -or $2ndlast -eq 'run') {
$runCompletions = & $GetNpmRunRef
# note that we prepend it to our options array, because I like to prioritize it this way
}

# Read through all <.*> values, and parse them according to our helpers
# foreach ($possible in $currently_at.Keys) {
# if ($possible -match "<command>") {
# $evaluated += & $GetNpmRunRef
# }
# }

# attempt to use -like
$options = $currently_at.Keys
| Where-Object {$_ -like "$last*"}
Expand All @@ -382,18 +389,25 @@ function Get-CompletionsYarn {
$options += $evaluated
| Where-Object {$_ -like "$last*"}

$runCompletionsMaybe = $runCompletions | Where-Object {$_ -like "$last*"}
if ($runCompletionsMaybe.Count -gt 0) {
$options = @($runCompletionsMaybe + $options)
}

# if we failed fallback to the tree
if ($null -eq $options -or $options.Count -eq 0) {
$options = $currently_at.Keys
| Where-Object {-not ($_.StartsWith('$') -or $_.StartsWith('<'))}
| Sort-Object -Property { $_.Length }

$options += $evaluated
$options = @($runCompletions + $options)
}

$allOptions += $evaluated
$allOptions += $currently_at.Keys
| Where-Object {-not ($_.StartsWith('$') -or $_.StartsWith('<'))}
$allOptions = @($runCompletions + $allOptions)

# remove nullish values
$allOptions = $allOptions | Where-Object { $null -ne $_ }
Expand Down

0 comments on commit ae8093a

Please sign in to comment.