mirror of https://github.com/ray-x/go.nvim
Add command autocomplete
parent
51f4d41363
commit
ec91d9915f
@ -0,0 +1,23 @@
|
||||
local M = {}
|
||||
function M.list(mod, args)
|
||||
local cmd = {'go', 'list', '-json'}
|
||||
|
||||
local out
|
||||
if mod == false then
|
||||
table.insert(cmd, 1, 'GO111MODULE=off')
|
||||
end
|
||||
|
||||
vim.list_extend(cmd, args or {'.'})
|
||||
out = vim.fn.systemlist(table.concat(cmd, ' '))
|
||||
if vim.v.shell_error ~= 0 then
|
||||
return false
|
||||
end
|
||||
for i, e in ipairs(out) do
|
||||
if e == '}' and out[i + 1] == '{' then
|
||||
out[i] = '},'
|
||||
end
|
||||
end
|
||||
return true, vim.json.decode('[' .. table.concat(out, '') .. ']')
|
||||
end
|
||||
|
||||
return M
|
@ -0,0 +1,31 @@
|
||||
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')
|
||||
end
|
||||
}
|
Loading…
Reference in New Issue