diff options
| author | Opportunity <[email protected]> | 2020-01-16 20:20:39 +0800 |
|---|---|---|
| committer | Opportunity <[email protected]> | 2020-01-16 20:20:39 +0800 |
| commit | 19fef8183e250a49628a4281264753a7da1338dc (patch) | |
| tree | 9feffdbd051845b652bee70fdc1974b3820601a5 /xmake/modules/private/utils/complete.lua | |
| parent | 0ce4e75a38fbe5d4dc7688a4c65a56bf0a8d332d (diff) | |
fix complete
Diffstat (limited to 'xmake/modules/private/utils/complete.lua')
| -rw-r--r-- | xmake/modules/private/utils/complete.lua | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/xmake/modules/private/utils/complete.lua b/xmake/modules/private/utils/complete.lua index a1e8480df..70c54e056 100644 --- a/xmake/modules/private/utils/complete.lua +++ b/xmake/modules/private/utils/complete.lua @@ -23,6 +23,11 @@ import("core.base.option") import("core.base.task") local use_spaces = true +local raw_words = {} +local word = "" +local position = 0 +local has_space = false +local reenter = false function _print_candidate(is_complate, ...) local candidate = format(...) @@ -63,12 +68,25 @@ function _complete_option(options, segs, name) local current_options = try { function() - return option.raw_parse(segs, options, { populate_defaults = false }) + return option.raw_parse(segs, options, { populate_defaults = false, allow_unknown = true }) end } -- current options is invalid if not current_options then return end + -- current context is wrong + if not reenter and (current_options.file or current_options.project) then + local args = {"lua", "--root", "private.utils.complete", tostring(position), use_spaces and "reenter" or "nospace-reenter", table.unpack(raw_words) } + if current_options.file then + table.insert(args, 3, "--file=" .. current_options.file) + end + if current_options.project then + table.insert(args, 3, "--project=" .. current_options.project) + end + os.execv("xmake", args) + return + end + local state = 0 if name == "-" or name == "--" then name = "" @@ -112,28 +130,7 @@ function _complete_option(options, segs, name) end end -function main(position, config_use_spaces, ...) - local words = {...} - if config_use_spaces == "nospace" then - use_spaces = false - else - table.insert(words, 1, config_use_spaces) - end - - local word = table.concat(words, " ") or "" - position = tonumber(position) or 0 - local has_space = word:endswith(" ") or position > #word - word = word:trim() - - if is_host("windows") then - if word:lower():startswith("xmake.exe") then - word = "xmake" .. word:sub(#"xmake.exe" + 1) - end - end - - if word:lower():startswith("xmake ") then - word = word:sub(#"xmake " + 1) - end +function _complete() local tasks = {} local shortnames = {} @@ -167,4 +164,42 @@ function main(position, config_use_spaces, ...) if not has_space then segs[#segs] = nil end _complete_option(tasks[task_name].options, segs, incomplete_option) +end + +function main(pos, config, ...) + + raw_words = {...} + local words = {...} + + local is_config = false + if config:find("nospace", 1, true) then + use_spaces = false + is_config = true + end + if config:find("reenter", 1, true) then + reenter = true + is_config = true + end + + if not is_config then + table.insert(words, 1, config) + end + + word = table.concat(words, " ") or "" + position = tonumber(pos) or 0 + has_space = word:endswith(" ") or position > #word + word = word:trim() + + -- normailize word to "xmake ..." + if is_host("windows") then + if word:lower():startswith("xmake.exe") then + word = "xmake" .. word:sub(#"xmake.exe" + 1) + end + end + + if word:lower():startswith("xmake ") then + word = word:sub(#"xmake " + 1) + end + + _complete() end
\ No newline at end of file |
