2021-11-13 03:29:42 +00:00
|
|
|
local golist = require'go.list'.list
|
|
|
|
local util = require 'go.utils'
|
|
|
|
local log = util.log
|
|
|
|
return {
|
|
|
|
complete = function()
|
|
|
|
local ok, l = golist(false, {util.all_pkgs()})
|
|
|
|
if not ok then
|
|
|
|
log('Failed to find all packages for current module/project.')
|
|
|
|
end
|
|
|
|
local curpkgmatch = false
|
|
|
|
local curpkg = vim.fn.fnamemodify(vim.fn.expand('%'), ':h:.')
|
|
|
|
local pkgs = {}
|
|
|
|
for _, p in ipairs(l) do
|
|
|
|
local d = vim.fn.fnamemodify(p.Dir, ':.')
|
|
|
|
if curpkg ~= d then
|
|
|
|
if d ~= vim.fn.getcwd() then
|
|
|
|
table.insert(pkgs, util.relative_to_cwd(d))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
curpkgmatch = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.sort(pkgs)
|
|
|
|
table.insert(pkgs, util.all_pkgs())
|
|
|
|
table.insert(pkgs, '.')
|
|
|
|
if curpkgmatch then
|
|
|
|
table.insert(pkgs, util.relative_to_cwd(curpkg))
|
|
|
|
end
|
|
|
|
return table.concat(pkgs, '\n')
|
2021-11-23 23:13:40 +00:00
|
|
|
end,
|
|
|
|
all_pkgs = function()
|
|
|
|
local ok, l = golist(false, {util.all_pkgs()})
|
|
|
|
if not ok then
|
|
|
|
log('Failed to find all packages for current module/project.')
|
|
|
|
end
|
|
|
|
return l
|
2021-11-13 03:29:42 +00:00
|
|
|
end
|
2021-11-23 23:13:40 +00:00
|
|
|
|
2021-11-13 03:29:42 +00:00
|
|
|
}
|