Closed willyd closed 9 years ago
Hi,
I am trying to add some completion to cmake.exe which has some options that are normal powershell parameter with a single hyphen:
cmake -G "Generator"
but some others have double hyphens li
cmake --build .
I can't seem to find how to support the double hyphen type. Any ideas on how this can be acheived? Here is the code I have now:
function CMakeCompletion { [ArgumentCompleter( Native, Command = 'cmake', Description = 'Complete arguments to cmake.exe' )] param( $wordToComplete, $commandAst ) $tryParameters = $true $last = if ($wordToComplete) { -2 } else { -1 } $parameterAst = $commandAst.CommandElements[$last] -as [System.Management.Automation.Language.CommandParameterAst] if ($parameterAst -ne $null) { # remove the quotes from word to complete if any # this is necessary as some of the generators have # white spaces in them. $wordToComplete = $wordToComplete.Replace("'", "") $completions = $null if ("G".StartsWith($parameterAst.ParameterName, "OrdinalIgnoreCase")) { $VisualStudioVersion = '10 2010', '11 2012', '12 2013', '14 2015' $VSGenerators = $VisualStudioVersion | % {"Visual Studio $_", "Visual Studio $_ Win64"} $CMakeGenerators = $VSGenerators + @('NMake Makefiles', 'MinGW Makefiles', 'Ninja', 'Sublime Text 2 - Ninja', 'Sublime Text 2 - Ninja', 'Sublime Text 2 - MinGW Makefiles') $completions = $CMakeGenerators } if("D".StartsWith($parameterAst.ParameterName, "OrdinalIgnoreCase")) { $CMakeCommonDefinitions = @('BUILD_SHARED_LIBS=OFF', 'BUILD_SHARED_LIBS=ON', 'CMAKE_BUILD_TYPE=Release', 'CMAKE_BUILD_TYPE=Debug') $completions = $CMakeCommonDefinitions } # I can't get powershell to get here with the --build parameter! $tryParameters = ($completions.Length -eq 0) $completions | Where-Object { $_ -match "^$wordToComplete"} | ForEach-Object { New-CompletionResult $_ } } if ($tryParameters -and ($wordToComplete.StartsWith("-") -or "" -eq $wordToComplete)) { echo -- -G -D --build | Where-Object { $_ -like "$wordToComplete*" } | Sort-Object | ForEach-Object { New-CompletionResult $_ } } }
PowerShell parses tokens starting with -- as an argument, not a parameter. So you'll have to also look at command elements of type StringConstantExpression where the Value starts with --.
Hi,
I am trying to add some completion to cmake.exe which has some options that are normal powershell parameter with a single hyphen:
but some others have double hyphens li
I can't seem to find how to support the double hyphen type. Any ideas on how this can be acheived? Here is the code I have now: