Bugfix issue #15 GoRun

This commit is contained in:
ray-x 2021-07-17 00:37:41 +10:00
parent af37cb81b8
commit e7a7e95c85
2 changed files with 29 additions and 13 deletions

View File

@ -45,12 +45,13 @@ function go.setup(cfg)
vim.cmd([[command! Gofmt lua require("go.format").gofmt()]])
vim.cmd([[command! Goimport lua require("go.format").goimport()]])
vim.cmd([[command! GoBuild :setl makeprg=go\ build | :GoMake]])
vim.cmd([[command! GoGenerate :setl makeprg=go\ generate | :GoMake]])
vim.cmd([[command! GoRun :setl makeprg=go\ run | :GoMake]])
vim.cmd([[command! GoTest :setl makeprg=go\ test\ -v\ ./... | :GoMake]])
vim.cmd([[command! GoGenerate :setl makeprg=go\ generate | :GoMake]])
vim.cmd(
[[command! -nargs=* GoBuild :setl makeprg=go\ build | lua require'go.asyncmake'.make(<f-args>)]])
vim.cmd(
[[command! -nargs=* GoRun :setl makeprg=go\ run | lua require'go.asyncmake'.make(<f-args>)]])
vim.cmd(
[[command! -nargs=* GoTest :setl makeprg=go\ test\ | lua require'go.asyncmake'.make(<f-args>)]])
-- vim.cmd([[command! GoTestCompile :setl makeprg=go\ build | :GoMake]])
vim.cmd([[command! GoLint :setl makeprg=golangci-lint\ run\ --out-format\ tab | :GoMake]])

View File

@ -1,31 +1,46 @@
-- https://phelipetls.github.io/posts/async-make-in-nvim-with-lua/
local M = {}
function M.make()
function M.make(...)
local args = {...}
local lines = {""}
local winnr = vim.fn.win_getid()
local bufnr = vim.api.nvim_win_get_buf(winnr)
local makeprg = vim.api.nvim_buf_get_option(bufnr, "makeprg")
local indent = '%\\%( %\\)'
if not makeprg then
return
end
vim.cmd([[setl errorformat =%-G#\ %.%#]])
if makeprg == "go build" then
if makeprg:find("go build") then
vim.cmd([[setl errorformat+=%-G%.%#panic:\ %m]])
vim.cmd([[setl errorformat+=%Ecan\'t\ load\ package:\ %m]])
vim.cmd([[setl errorformat+=%A%\\%%(%[%^:]%\\+:\ %\\)%\\?%f:%l:%c:\ %m]])
vim.cmd([[setl errorformat+=%A%\\%%(%[%^:]%\\+:\ %\\)%\\?%f:%l:\ %m]])
vim.cmd([[setl errorformat+=%C%*\\s%m]])
vim.cmd([[setl errorformat+=%-G%.%#]])
else
end
if makeprg:find('golangci-lint') then
-- lint
vim.cmd([[setl errorformat+=%-G#\ %.%#,%f:%l:%c:\\?\ %m]])
end
if not makeprg then
return
if makeprg == 'go run' and #args == 0 then
vim.cmd([[setl makeprg=go\ run\ \.]])
makeprg = makeprg .. ' .'
vim.api.nvim_buf_set_option(bufnr, 'makeprg', makeprg)
end
local arg = ' '
for _, v in pairs(args or {}) do
arg = arg .. ' ' .. v
end
if #arg then
makeprg = makeprg .. arg
vim.api.nvim_buf_set_option(bufnr, 'makeprg', makeprg)
end
local cmd = vim.fn.expandcmd(makeprg)
local function on_event(job_id, data, event)