summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorGly <[email protected]>2022-12-22 01:22:28 +0100
committerGly <[email protected]>2022-12-22 01:22:28 +0100
commit95ee81deecf956d4f87a2315ffa55996c41bfa2a (patch)
treefc7272f6a50f493b06a997edd6080acba108c83f /xmake/modules
parent524a23ae6a0a5fcdd23c8c32a52ab62bcd07830b (diff)
complete options
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/private/utils/complete.lua27
1 files changed, 14 insertions, 13 deletions
diff --git a/xmake/modules/private/utils/complete.lua b/xmake/modules/private/utils/complete.lua
index dd396572e..072c69704 100644
--- a/xmake/modules/private/utils/complete.lua
+++ b/xmake/modules/private/utils/complete.lua
@@ -121,13 +121,15 @@ function _complete_option_kv_v(options, current, completing, name, value)
end
-- match values starts with value first
+ local found_candidates = {}
for _, v in ipairs(_find_candidates(values, value)) do
if no_key then
- _print_candidate(true, "%s", v)
+ table.insert(found_candidates, { value = v, is_complete = true })
else
- _print_candidate(true, "--%s=%s", name, v)
+ table.insert(found_candidates, { value = format("--%s=%s", name, v), is_complete = true })
end
end
+ _print_candidates(found_candidates)
-- whether any candidates has been found, finish complete since we don't have more info
return true
@@ -142,11 +144,13 @@ function _complete_option_kv_k(options, current, completing, name)
opcandi[opt[2]] = opt
end
end
-
+ local found_candidates = {}
for _, k in ipairs(_find_candidates((table.keys(opcandi)), name)) do
local opt = opcandi[k]
- _print_candidate((opt[3] == "k"), (opt[3] == "k") and "--%s" or "--%s=", opt[2])
+ local name = format((opt[3] == "k") and "--%s" or "--%s=", opt[2])
+ table.insert(found_candidates, { value = name, description = opt[5], is_complete = (opt[3] == "k") })
end
+ _print_candidates(found_candidates)
return true
end
@@ -190,7 +194,7 @@ function _complete_option_v(options, current, completing)
optvs = v
end
end
-
+ local found_candidates = {}
if opt then
-- show candidates of values
local values = opt.values
@@ -199,14 +203,12 @@ function _complete_option_v(options, current, completing)
end
for _, v in ipairs(values) do
if tostring(v):startswith(completing) then
- _print_candidate(true, "%s", v)
+ table.insert(found_candidates, { value = v, is_complete = true })
end
end
- return true
end
- if optvs then
-
+ if optvs and #found_candidates == 0 then
-- show candidates of values
local values = optvs.values
if type(values) == "function" then
@@ -214,13 +216,12 @@ function _complete_option_v(options, current, completing)
end
for _, v in ipairs(values) do
if tostring(v):startswith(completing) then
- _print_candidate(true, "%s", v)
+ table.insert(found_candidates, { value = v, is_complete = true })
end
end
- return true
end
-
- return false
+ _print_candidates(found_candidates)
+ return #found_candidates > 0
end
function _complete_option(options, segs, completing)