Created
May 8, 2019 02:07
-
-
Save lzybkr/06f033df7c9ca8aa7628f64d28187acf to your computer and use it in GitHub Desktop.
# Autocompletion for clang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Autocompletion for clang - only works in pwsh | |
Register-ArgumentCompleter -CommandName clang -Native -ScriptBlock { | |
param($wordToComplete, $commandAst) | |
if ($wordToComplete.StartsWith('-')) { | |
$p,$a = $wordToComplete -split '=',2 | |
if ($null -ne $a) { | |
$clangArg = "$p=,$a" | |
$type = [System.Management.Automation.CompletionResultType]::ParameterValue | |
} else { | |
$clangArg = $p | |
$type = [System.Management.Automation.CompletionResultType]::ParameterName | |
} | |
foreach ($completion in clang --autocomplete=$clangArg) { | |
$text,$tooltip = $completion -split "\s+", 2 | |
if (!$tooltip) { $tooltip = $text } | |
$listItem = $text | |
if ($null -ne $a) { | |
$text = "$p=$text" | |
} | |
[System.Management.Automation.CompletionResult]::new($text, $listItem, $type, $toolTip) | |
} | |
} | |
# TODO: complete files based on extension, e.g. only c/cpp files? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment