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
return vim.ui.select
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
lsp_inlay_hints = {
enable = true,

@ -63,16 +63,17 @@ function M.make(...)
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(
'makeprg is already set to ' .. makeprg .. ' args: ' .. vim.inspect(args),
vim.log.levels.WARN
)
end
-- local indent = "%\\%( %\\)"
if not makeprg then
log('makeprog not setup')
return
makeprg = 'go'
end
local runner = vim.split(makeprg, ' ')[1]

@ -136,10 +136,9 @@ return {
end, { nargs = '*' })
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))
end, {
})
end, {})
create_cmd('GoImports', function(opts)
require('go.format').goimports(unpack(opts.fargs))
end, {
@ -171,11 +170,22 @@ return {
gobin
)
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(
[[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
)
utils.log(cmd)
vim.cmd(cmd)
create_cmd('GoStop', function(opts)
@ -487,7 +497,7 @@ return {
nargs = '*',
complete = function(_, _, _)
-- return completion candidates as a list-like table
return { 'generate', 'bootstrap', 'build', 'labels', 'run', 'watch'}
return { 'generate', 'bootstrap', 'build', 'labels', 'run', 'watch' }
end,
})
create_cmd('GinkgoFunc', function(opts)

Loading…
Cancel
Save