diff options
| author | Gly <[email protected]> | 2022-12-26 17:39:22 +0100 |
|---|---|---|
| committer | Gly <[email protected]> | 2022-12-26 17:39:22 +0100 |
| commit | f904c3a71dcbd409e0fda27bd5d70da0da0146a3 (patch) | |
| tree | 2e59bb014a4e2f2ab586da8375e6d56bf9b52c04 /xmake/modules/private/utils/completer.lua | |
| parent | 07b1c4d4f85f4b887e96ce3d42636ac0337dacfc (diff) | |
completer takes values as string or objects
Diffstat (limited to 'xmake/modules/private/utils/completer.lua')
| -rw-r--r-- | xmake/modules/private/utils/completer.lua | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/xmake/modules/private/utils/completer.lua b/xmake/modules/private/utils/completer.lua index 2d882c9e3..b4560ff82 100644 --- a/xmake/modules/private/utils/completer.lua +++ b/xmake/modules/private/utils/completer.lua @@ -201,6 +201,25 @@ function completer:_complete_option_v(options, current, completing) optvs = v end end + + local function find_and_add_candidates(values) + local found_candidates = {} + if #values > 0 and type(values[1]) == "string" then + for _, v in ipairs(values) do + if tostring(v):startswith(completing) then + table.insert(found_candidates, { value = v, is_complete = true }) + end + end + else + for _, v in ipairs(values) do + if v.value:startswith(completing) then + v.is_complete=true + table.insert(found_candidates, v) + end + end + end + return found_candidates + end local found_candidates = {} if opt then -- show candidates of values @@ -208,11 +227,7 @@ function completer:_complete_option_v(options, current, completing) if type(values) == "function" then values = values(completing, current) end - for _, v in ipairs(values) do - if tostring(v):startswith(completing) then - table.insert(found_candidates, { value = v, is_complete = true }) - end - end + found_candidates = find_and_add_candidates(values) end if optvs and #found_candidates == 0 then @@ -221,11 +236,7 @@ function completer:_complete_option_v(options, current, completing) if type(values) == "function" then values = values(completing) end - for _, v in ipairs(values) do - if tostring(v):startswith(completing) then - table.insert(found_candidates, { value = v, is_complete = true }) - end - end + found_candidates = find_and_add_candidates(values) end self:_print_candidates(found_candidates) return #found_candidates > 0 |
