feature: add preludes for GoRun; Simplify asyncmake;

pull/479/head
ray-x 4 months ago
parent b779debab8
commit b3ee7aea17

@ -68,6 +68,13 @@ _GO_NVIM_CFG = {
end end
return vim.ui.select return vim.ui.select
end, end,
preludes = { -- experimental feature, set to empty to disable; set to function to enable
default = function() return {} end, -- one for all commands
GoRun = function() -- the commands to run before GoRun, this override default
return {} -- e.g. return {'watchexe', '--restart', '-v', '-e', 'go'}
-- so you will run `watchexe --restart -v -e go go run `
end
},
-- deprecated setups -- deprecated setups
lsp_inlay_hints = { lsp_inlay_hints = {
enable = true, enable = true,

@ -63,16 +63,17 @@ function M.make(...)
end end
end end
end end
if vim.fn.empty(makeprg) == 0 and args[1] == 'go' then -- local indent = "%\\%( %\\)"
if vim.fn.empty(makeprg) == 1 then
log('makeprog not setup')
return
end
if args[1] == 'go' then
vim.notify( vim.notify(
'makeprg is already set to ' .. makeprg .. ' args: ' .. vim.inspect(args), 'makeprg is already set to ' .. makeprg .. ' args: ' .. vim.inspect(args),
vim.log.levels.WARN vim.log.levels.WARN
) )
end makeprg = 'go'
-- local indent = "%\\%( %\\)"
if not makeprg then
log('makeprog not setup')
return
end end
local runner = vim.split(makeprg, ' ')[1] local runner = vim.split(makeprg, ' ')[1]

@ -136,10 +136,9 @@ return {
end, { nargs = '*' }) end, { nargs = '*' })
create_cmd('GoImport', function(opts) create_cmd('GoImport', function(opts)
vim.notify('GoImport is deprecated, use GoImports' ) vim.notify('GoImport is deprecated, use GoImports')
require('go.format').goimports(unpack(opts.fargs)) require('go.format').goimports(unpack(opts.fargs))
end, { end, {})
})
create_cmd('GoImports', function(opts) create_cmd('GoImports', function(opts)
require('go.format').goimports(unpack(opts.fargs)) require('go.format').goimports(unpack(opts.fargs))
end, { end, {
@ -171,11 +170,22 @@ return {
gobin gobin
) )
vim.cmd(cmd) vim.cmd(cmd)
local pcmdstr = ''
local preludes = _GO_NVIM_CFG.preludes
local gorun_preludes = preludes.GoRun or preludes.default
if gorun_preludes ~= nil then
local pcmd = gorun_preludes()
if #pcmd > 0 then
pcmdstr = table.concat(pcmd, '\\ ') .. '\\ '
end
end
cmd = string.format( cmd = string.format(
[[command! -nargs=* -complete=customlist,v:lua.package.loaded.go.package_complete GoRun :setl makeprg=%s\ run | lua require'go.asyncmake'.make(<f-args>)]], [[command! -nargs=* -complete=customlist,v:lua.package.loaded.go.package_complete GoRun :setl makeprg=%s%s\ run | lua require'go.asyncmake'.make(<f-args>)]],
pcmdstr,
gobin gobin
) )
utils.log(cmd)
vim.cmd(cmd) vim.cmd(cmd)
create_cmd('GoStop', function(opts) create_cmd('GoStop', function(opts)
@ -487,7 +497,7 @@ return {
nargs = '*', nargs = '*',
complete = function(_, _, _) complete = function(_, _, _)
-- return completion candidates as a list-like table -- return completion candidates as a list-like table
return { 'generate', 'bootstrap', 'build', 'labels', 'run', 'watch'} return { 'generate', 'bootstrap', 'build', 'labels', 'run', 'watch' }
end, end,
}) })
create_cmd('GinkgoFunc', function(opts) create_cmd('GinkgoFunc', function(opts)

Loading…
Cancel
Save