LazyCompletions.Self.ps1

###-begin-lazycompletions-self-completion-###
# template-version: 6

# ==============================================================================
# lazycompletions.ps1 - Parameter completion for the LazyCompletions module itself (bootstrap)
#
# Unified management: this script works exactly like pnpm.ps1 / uv.ps1 — it is scanned
# automatically by the module, loaded lazily (only on the first Tab), and managed uniformly
# (visible in Get-LazyCompletion). The module manages its own completion with no special
# code path.
#
# Generated by Add-LazyCompletion -Self from the bundled template.
# Dependency: when triggered, the module is necessarily imported (otherwise these functions
# would not exist); command names come from the public API Get-LazyCompletion, no internal
# state is used.
# ==============================================================================

# --- Get-LazyCompletion -Command: complete registered command names (incl. aliases, e.g. uv / pn / pnpm) ---
# Note: parameter-level completers must use the 5-arg signature (the engine calls them that
# way); general completers use 3 args
Register-ArgumentCompleter -CommandName 'Get-LazyCompletion' -ParameterName 'Command' -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
    @(Get-LazyCompletion | ForEach-Object { $_.Commands -split ', ' }) |
        Where-Object { $_ -and $_ -like "$wordToComplete*" } |
        Sort-Object -Unique |
        ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', "Registered command: $_")
        }
}

# --- Directory path completion (Set-LazyCompletionsPath -Path, Add-LazyCompletion -Directory, Set-LazyCache -Path) ---
# Local variables (the script is dot-sourced into the module scope; no $script: prefix to avoid
# polluting the module namespace)
$DirPathCompleter = {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
    $parent = if ($wordToComplete) {
        $p = Split-Path $wordToComplete -Parent -ErrorAction SilentlyContinue
        if ($p) { $p } else { (Get-Location).Path }
    } else {
        (Get-Location).Path
    }
    [System.IO.Directory]::GetDirectories($parent) |
        Where-Object { $_ -like "$wordToComplete*" } |
        ForEach-Object {
            [System.Management.Automation.CompletionResult]::new(
                $_, [System.IO.Path]::GetFileName($_), 'ProviderContainer', $_)
        }
}

Register-ArgumentCompleter -CommandName 'Set-LazyCompletionsPath' -ParameterName 'Path' -ScriptBlock $DirPathCompleter
Register-ArgumentCompleter -CommandName 'Add-LazyCompletionsPath' -ParameterName 'Path' -ScriptBlock $DirPathCompleter
Register-ArgumentCompleter -CommandName 'Add-LazyCompletion'  -ParameterName 'Directory' -ScriptBlock $DirPathCompleter
Register-ArgumentCompleter -CommandName 'Set-LazyCache'       -ParameterName 'Path' -ScriptBlock $DirPathCompleter

# --- Add-LazyCompletion -Name: complete registered command names (regenerate/overwrite scenarios) ---
Register-ArgumentCompleter -CommandName 'Add-LazyCompletion' -ParameterName 'Name' -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
    @(Get-LazyCompletion | ForEach-Object { $_.Commands -split ', ' }) |
        Where-Object { $_ -and $_ -like "$wordToComplete*" } |
        Sort-Object -Unique |
        ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', "Registered command: $_")
        }
}

###-end-lazycompletions-self-completion-###