diff --git a/lua/go.lua b/lua/go.lua index 0b6b5b1..31e9b43 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -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, diff --git a/lua/go/asyncmake.lua b/lua/go/asyncmake.lua index 2e81b77..af384ea 100644 --- a/lua/go/asyncmake.lua +++ b/lua/go/asyncmake.lua @@ -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] diff --git a/lua/go/commands.lua b/lua/go/commands.lua index 4fcc920..336eeea 100644 --- a/lua/go/commands.lua +++ b/lua/go/commands.lua @@ -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()]], + [[command! -nargs=* -complete=customlist,v:lua.package.loaded.go.package_complete GoRun :setl makeprg=%s%s\ run | lua require'go.asyncmake'.make()]], + 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)