lzybkr / TabExpansionPlusPlus

A V3 PowerShell module to improve tab expansion and Intellisense
BSD 2-Clause "Simplified" License
196 stars 33 forks source link

exe or cmd complition #64

Closed czhang03 closed 8 years ago

czhang03 commented 8 years ago

I was trying to write a completion for hexo.

function HexoArgumentCompletion{
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

    echo $commandName
    echo 'next param'
    echo $parameterName
    echo 'next word to compl'
    echo $wordToComplete
    $HexoCommandList = @('help', 'init', 'version', 'new')

    $HexoCommandList|ForEach-Object {
        if($_ -match "$wordToComplete*") {
            New-CompletionResult -CompletionText $_
        }    
    }
}

Register-ArgumentCompleter `
    -Native `
    -CommandName ('hexo') `
    -ScriptBlock $function:HexoArgumentCompletion

I found out that the $commandName is null, the $parameterName is what inputed. for example, if I write hexo ne<tab>, $parameter name is 'hexo ne' the $wordToComplete is the cursor position.

I don't know why, is it related to the -Native parameter of Register-ArgumentCompleter?

czhang03 commented 8 years ago

this works...

function HexoArgumentCompletion{
    param($commandName, $wordToComplete, $commandAst, $fakeBoundParameter)

    $command = 'hexo'
    $HexoCommandList = @('help', 'init', 'version', 'new', 'ntest')

    $HexoCommandList|ForEach-Object {
        if("$command $_" -match "$wordToComplete *") {
            New-CompletionResult -CompletionText $_
        }    
    }
}

Register-ArgumentCompleter `
    -Native `
    -CommandName ('hexo', 'hexo.cmd') `
    -ScriptBlock $function:HexoArgumentCompletion

but I don't know why...

czhang03 commented 8 years ago

I will open a new issue to state this