diff options
| author | OpportunityLiu <[email protected]> | 2019-06-05 21:15:28 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-06-05 21:15:28 +0800 |
| commit | 2fc0ed7ad1d2af134d1b25334634f1050bb42376 (patch) | |
| tree | 217dd8eab7a5b7aa127da497554f6ca878d9ec9a | |
| parent | 1b5017a88667c5af7a4afd4311d4861eb540b1bb (diff) | |
fix for powershell
| -rw-r--r-- | scripts/register-completions.ps1 | 7 | ||||
| -rw-r--r-- | xmake/modules/private/utils/complete.lua | 10 |
2 files changed, 11 insertions, 6 deletions
diff --git a/scripts/register-completions.ps1 b/scripts/register-completions.ps1 index 58e11320a..6295cf4fc 100644 --- a/scripts/register-completions.ps1 +++ b/scripts/register-completions.ps1 @@ -2,7 +2,12 @@ Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock { param($commandName, $wordToComplete, $cursorPosition) - xmake lua private.utils.complete "$cursorPosition" "$wordToComplete" | ForEach-Object { + $complete = "$wordToComplete" + if (-not $commandName) { + $complete = $complete + " " + } + xmake lua private.utils.complete "0" "$complete" | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } + diff --git a/xmake/modules/private/utils/complete.lua b/xmake/modules/private/utils/complete.lua index 5c85482fb..df3e98e3f 100644 --- a/xmake/modules/private/utils/complete.lua +++ b/xmake/modules/private/utils/complete.lua @@ -95,9 +95,9 @@ end function main(position, ...) word = table.concat({...}, " ") or "" position = tonumber(position) or 0 - if position > #word then - word = word .. " " - end + local has_space = word:endswith(" ") or position > #word + word = word:trim() + if word:lower():startswith("xmake ") then word = word:sub(#"xmake " + 1) end @@ -107,7 +107,7 @@ function main(position, ...) local segs = word:split("%s") local task = table.remove(segs, 1) or "" - if #segs == 0 and not word:endswith(" ") then + if #segs == 0 and not has_space then if _complete_task(task) then return end end @@ -116,6 +116,6 @@ function main(position, ...) table.insert(segs, 1, task) task = "run" end - _complete_option(option.taskmenu(task).options, word:endswith(" ") and "" or segs[#segs]) + _complete_option(option.taskmenu(task).options, has_space and "" or segs[#segs]) return end
\ No newline at end of file |
