From a237ad160532834578ee7021df9f08cf99e0a2ea Mon Sep 17 00:00:00 2001 From: "Bak, Jin Hyeong" Date: Wed, 23 Aug 2017 14:22:29 +0900 Subject: [PATCH] Add autocompletion for the '--explain' option --- posh-cargo.psm1 | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/posh-cargo.psm1 b/posh-cargo.psm1 index 4473e13..5821d60 100644 --- a/posh-cargo.psm1 +++ b/posh-cargo.psm1 @@ -80,6 +80,25 @@ function get_available_target_triples($toolchain) { return $targets | Where-Object { $_ -match $pattern } | ForEach-Object { $_ -replace $pattern, '' } } +function get_toolchain_path($toolchain) { + $rustc_path = '' + if ($toolchain) { + $rustc_path = $(rustup run $toolchain rustup which rustc) + } + else { + $rustc_path = $(rustup which rustc) + } + return Resolve-Path ((Split-Path $rustc_path) + '\..') +} + +function get_rustc_errorcode_list($toolchain) { + $toolchain_path = (get_toolchain_path $toolchain) + $doc_path = Join-Path $toolchain_path 'share\doc\rust\html\error-index.html' + Get-Content $doc_path | Where-Object { + $_ -match 'error-described error-used\">

\S*)$") { - $wordToComplete = $Matches['lastToken'] - $completionList = $color + if ($parameters -match '(^|\s+)(?\-\S+)\s+(?\S*)$') { + $lastToken = $Matches['lastToken'] + $lastOption = $Matches['lastOption'] + switch -regex ($lastOption) { + '^\-\-color$' { + $wordToComplete = $lastToken + $completionList = $color + } + '^\-\-explain$' { + $wordToComplete = $lastToken + $completionList = (get_rustc_errorcode_list $toolchain) + if (!$completionList) { + $completionList = @('') + } + } + } } }