2023-05-20 10:26:33 +00:00
|
|
|
-- inspired by https://phelipetls.github.io/posts/async-make-in-nvim-with-lua/
|
2021-04-19 06:10:06 +00:00
|
|
|
local M = {}
|
2023-09-07 08:12:43 +00:00
|
|
|
local util = require('go.utils')
|
2021-12-11 03:44:15 +00:00
|
|
|
local log = util.log
|
2022-07-07 16:34:50 +00:00
|
|
|
local trace = util.trace
|
2023-09-07 08:12:43 +00:00
|
|
|
local getopt = require('go.alt_getopt')
|
2022-01-17 06:33:00 +00:00
|
|
|
|
2023-05-20 10:26:33 +00:00
|
|
|
local os_name = vim.loop.os_uname().sysname
|
|
|
|
local is_windows = os_name == 'Windows' or os_name == 'Windows_NT'
|
2023-09-07 08:12:43 +00:00
|
|
|
local is_git_shell = is_windows
|
|
|
|
and (vim.fn.exists('$SHELL') and vim.fn.expand('$SHELL'):find('bash.exe') ~= nil)
|
2023-05-20 10:26:33 +00:00
|
|
|
|
2022-01-17 06:33:00 +00:00
|
|
|
local function compile_efm()
|
|
|
|
local efm = [[%-G#\ %.%#]]
|
|
|
|
efm = efm .. [[,%-G%.%#panic:\ %m]]
|
|
|
|
efm = efm .. [[,%Ecan\'t\ load\ package:\ %m]]
|
|
|
|
efm = efm .. [[,%A%\\%%\(%[%^:]%\\+:\ %\\)%\\?%f:%l:%c:\ %m]]
|
|
|
|
efm = efm .. [[,%A%\\%%\(%[%^:]%\\+:\ %\\)%\\?%f:%l:\ %m]]
|
|
|
|
efm = efm .. [[,%C%*\\s%m]]
|
|
|
|
efm = efm .. [[,%-G%.%#]]
|
|
|
|
return efm
|
|
|
|
end
|
|
|
|
|
2023-01-15 09:24:48 +00:00
|
|
|
local extract_filepath = util.extract_filepath
|
2022-02-23 10:01:19 +00:00
|
|
|
|
2022-05-16 23:47:45 +00:00
|
|
|
local long_opts = {
|
2023-09-07 08:12:43 +00:00
|
|
|
verbose = 'v',
|
|
|
|
compile = 'c',
|
2023-03-12 12:34:41 +00:00
|
|
|
debug = 'g', -- build for debugging
|
2023-02-21 15:51:10 +00:00
|
|
|
coverprofile = 'C',
|
2023-09-07 08:12:43 +00:00
|
|
|
tags = 't',
|
|
|
|
args = 'a',
|
|
|
|
count = 'n',
|
2023-09-22 10:56:38 +00:00
|
|
|
build = 'b',
|
2023-09-07 08:12:43 +00:00
|
|
|
run = 'r',
|
|
|
|
floaterm = 'F',
|
|
|
|
fuzz = 'f',
|
2022-05-16 23:47:45 +00:00
|
|
|
}
|
|
|
|
|
2023-10-31 05:30:38 +00:00
|
|
|
local short_opts = 'a:ct:b:Fg'
|
2023-09-07 08:12:43 +00:00
|
|
|
local bench_opts = { '-benchmem', '-cpuprofile', 'profile.out' }
|
2022-05-16 23:47:45 +00:00
|
|
|
|
2021-07-16 14:37:41 +00:00
|
|
|
function M.make(...)
|
2021-12-10 00:43:59 +00:00
|
|
|
local args = { ... }
|
2021-04-19 06:10:06 +00:00
|
|
|
local winnr = vim.fn.win_getid()
|
|
|
|
local bufnr = vim.api.nvim_win_get_buf(winnr)
|
2023-09-07 08:12:43 +00:00
|
|
|
local makeprg = vim.api.nvim_buf_get_option(bufnr, 'makeprg')
|
2021-12-10 00:43:59 +00:00
|
|
|
|
2022-06-01 11:29:13 +00:00
|
|
|
local optarg, _, reminder = getopt.get_opts(args, short_opts, long_opts)
|
2023-01-09 10:07:49 +00:00
|
|
|
log(makeprg, args, short_opts, optarg, reminder)
|
2023-03-12 12:34:41 +00:00
|
|
|
if reminder and #reminder > 0 then
|
|
|
|
-- expand % to current file
|
|
|
|
for i, arg in ipairs(reminder) do
|
2023-09-07 08:12:43 +00:00
|
|
|
if arg:find('%%') then
|
|
|
|
if arg == '%' then
|
|
|
|
reminder[i] = vim.fn.expand('%')
|
|
|
|
elseif arg == '%:h' then
|
|
|
|
reminder[i] = './' .. vim.fn.expand('%:h') .. '/...'
|
2023-03-16 23:02:45 +00:00
|
|
|
else
|
|
|
|
reminder[i] = vim.fn.expand(arg)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- reminder[i] = arg:gsub("%%", vim.fn.expand("%"))
|
2023-03-12 12:34:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-01-31 21:28:06 +00:00
|
|
|
if vim.fn.empty(makeprg) == 0 and args[1] == 'go' then
|
2023-09-07 08:12:43 +00:00
|
|
|
vim.notify(
|
|
|
|
'makeprg is already set to ' .. makeprg .. ' args: ' .. vim.inspect(args),
|
|
|
|
vim.log.levels.WARN
|
|
|
|
)
|
2023-01-31 21:28:06 +00:00
|
|
|
end
|
2022-06-01 11:29:13 +00:00
|
|
|
-- local indent = "%\\%( %\\)"
|
2021-07-16 14:37:41 +00:00
|
|
|
if not makeprg then
|
2023-09-07 08:12:43 +00:00
|
|
|
log('makeprog not setup')
|
2021-07-16 14:37:41 +00:00
|
|
|
return
|
|
|
|
end
|
2021-04-19 06:10:06 +00:00
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
local runner = vim.split(makeprg, ' ')[1]
|
2022-06-30 16:44:39 +00:00
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
if not require('go.install').install(runner) then
|
|
|
|
util.warn('please wait for ' .. runner .. ' to be installed and re-run the command')
|
2022-06-30 16:44:39 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-12-15 08:02:22 +00:00
|
|
|
local efm = [[%-G#\ %.%#]]
|
2023-09-07 08:12:43 +00:00
|
|
|
if makeprg:find('go build') then
|
2021-12-10 00:43:59 +00:00
|
|
|
vim.cmd([[setl errorformat=%-G#\ %.%#]])
|
2021-12-15 08:02:22 +00:00
|
|
|
-- if makeprg:find("go build") then
|
2022-01-17 06:33:00 +00:00
|
|
|
efm = compile_efm()
|
2023-09-07 08:12:43 +00:00
|
|
|
if optarg['g'] then
|
|
|
|
makeprg = makeprg .. ' -gcflags="all=-N -l"'
|
2023-03-12 12:34:41 +00:00
|
|
|
end
|
2021-07-16 14:37:41 +00:00
|
|
|
end
|
2021-12-15 08:02:22 +00:00
|
|
|
-- end
|
2021-12-10 00:43:59 +00:00
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
local runner = 'golangci-lint'
|
|
|
|
if makeprg:find('golangci%-lint') then
|
2021-04-19 06:10:06 +00:00
|
|
|
-- lint
|
2021-12-15 08:02:22 +00:00
|
|
|
efm = efm .. [[,%A%\\%%(%[%^:]%\\+:\ %\\)%\\?%f:%l:%c:\ %m]]
|
|
|
|
efm = efm .. [[,%A%\\%%(%[%^:]%\\+:\ %\\)%\\?%f:%l:\ %m]]
|
2021-12-11 03:44:15 +00:00
|
|
|
|
2021-12-16 07:15:21 +00:00
|
|
|
local pwd = util.work_path()
|
2023-09-07 08:12:43 +00:00
|
|
|
local cfg = pwd .. '.golangci.yml'
|
2021-12-11 03:44:15 +00:00
|
|
|
|
|
|
|
if util.file_exists(cfg) then
|
|
|
|
makeprg = makeprg .. [[\ -c\ ]] .. cfg
|
2021-12-16 06:46:52 +00:00
|
|
|
-- vim.api.nvim_buf_set_option(bufnr, "makeprg", makeprg)
|
2021-12-11 03:44:15 +00:00
|
|
|
end
|
2021-04-19 06:10:06 +00:00
|
|
|
end
|
2022-01-17 06:33:00 +00:00
|
|
|
local compile_test = false
|
2022-09-05 00:56:42 +00:00
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
if makeprg:find('go run') then
|
|
|
|
runner = 'go run'
|
|
|
|
if args == nil or #args == 0 or (#args == 1 and args[1] == '-F') then
|
|
|
|
makeprg = makeprg .. ' .'
|
2021-12-15 08:02:22 +00:00
|
|
|
end
|
|
|
|
efm = efm .. [[,%A%\\t%#%f:%l\ +0x%[0-9A-Fa-f]%\\+]]
|
2021-12-16 06:46:52 +00:00
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
log('go run', makeprg)
|
2021-12-15 08:02:22 +00:00
|
|
|
end
|
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
if makeprg:find('go vet') then
|
|
|
|
runner = 'go vet'
|
2021-12-15 08:02:22 +00:00
|
|
|
if args == nil or #args == 0 then
|
2023-09-07 08:12:43 +00:00
|
|
|
makeprg = makeprg .. ' .'
|
2021-12-15 08:02:22 +00:00
|
|
|
end
|
2022-01-17 06:33:00 +00:00
|
|
|
|
|
|
|
efm = compile_efm()
|
2021-12-15 08:02:22 +00:00
|
|
|
efm = efm .. [[,%-Gexit\ status\ %\\d%\\+]]
|
2021-07-16 14:37:41 +00:00
|
|
|
end
|
2021-04-19 06:10:06 +00:00
|
|
|
|
2023-01-12 12:42:15 +00:00
|
|
|
if makeprg:find('generate') then
|
|
|
|
if args == nil or #args == 0 then
|
2023-09-07 08:12:43 +00:00
|
|
|
makeprg = makeprg .. ' ' .. vim.fn.expand('%')
|
2023-01-12 12:42:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
local cmd = vim.fn.split(makeprg, ' ')
|
|
|
|
if optarg['t'] then
|
|
|
|
local tag = optarg['t']
|
|
|
|
local f = tag:find('=')
|
2022-05-30 14:04:52 +00:00
|
|
|
if not f then
|
2023-09-07 08:12:43 +00:00
|
|
|
table.insert(cmd, '-tags=' .. tag)
|
2022-05-30 14:04:52 +00:00
|
|
|
else
|
2023-09-07 08:12:43 +00:00
|
|
|
table.insert(cmd, '-tags=' .. tag:sub(f + 1))
|
2022-05-30 14:04:52 +00:00
|
|
|
end
|
|
|
|
end
|
2022-09-05 00:56:42 +00:00
|
|
|
|
|
|
|
local bench = false
|
2023-09-07 08:12:43 +00:00
|
|
|
if makeprg:find('go test') then
|
2023-10-31 05:30:38 +00:00
|
|
|
-- log('go test')
|
|
|
|
-- runner = 'go test'
|
|
|
|
-- efm = compile_efm()
|
|
|
|
-- if optarg['c'] then
|
|
|
|
-- log('compile test')
|
|
|
|
-- compile_test = true
|
|
|
|
-- end
|
|
|
|
-- for _, arg in ipairs(args) do
|
|
|
|
-- --check if it is bench test
|
|
|
|
-- if arg:find('-bench') then
|
|
|
|
-- bench = true
|
|
|
|
-- end
|
|
|
|
-- end
|
|
|
|
|
|
|
|
-- if optarg['v'] then
|
|
|
|
-- table.insert(cmd, '-v')
|
|
|
|
-- end
|
|
|
|
|
|
|
|
-- if optarg['C'] then
|
|
|
|
-- table.insert(cmd, '-coverprofile=' .. optarg['C'])
|
|
|
|
-- end
|
|
|
|
-- if optarg['f'] then
|
|
|
|
-- log('fuzz test')
|
|
|
|
-- table.insert(cmd, '-fuzz')
|
|
|
|
-- end
|
|
|
|
-- if optarg['n'] then
|
|
|
|
-- table.insert(cmd, '-count=' .. optarg['n'])
|
|
|
|
-- end
|
|
|
|
-- if not bench and compile_test then
|
|
|
|
-- table.insert(cmd, '-c')
|
|
|
|
-- end
|
|
|
|
-- if optarg['r'] then
|
|
|
|
-- log('run test', optarg['r'])
|
|
|
|
-- table.insert(cmd, '-run')
|
|
|
|
-- table.insert(cmd, optarg['r'])
|
|
|
|
-- end
|
|
|
|
-- if optarg['b'] then
|
|
|
|
-- log('build test flags', optarg['b'])
|
|
|
|
-- table.insert(cmd, optarg['b'])
|
|
|
|
-- end
|
2022-05-24 07:23:53 +00:00
|
|
|
end
|
2021-07-16 14:37:41 +00:00
|
|
|
|
2022-09-05 00:56:42 +00:00
|
|
|
if bench then
|
|
|
|
cmd = vim.list_extend(cmd, args)
|
|
|
|
elseif args and #args > 0 then
|
2022-05-16 23:47:45 +00:00
|
|
|
cmd = vim.list_extend(cmd, reminder)
|
2021-07-16 14:37:41 +00:00
|
|
|
end
|
2021-09-03 02:13:15 +00:00
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
if optarg['a'] then
|
2023-09-22 10:32:02 +00:00
|
|
|
if runner == 'go run' then
|
|
|
|
table.insert(cmd, optarg['a'])
|
|
|
|
else
|
|
|
|
table.insert(cmd, '-args')
|
|
|
|
table.insert(cmd, optarg['a'])
|
|
|
|
end
|
2022-10-22 12:39:48 +00:00
|
|
|
end
|
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
if _GO_NVIM_CFG.run_in_floaterm or optarg['F'] then
|
|
|
|
local term = require('go.term').run
|
2023-10-31 05:30:38 +00:00
|
|
|
local cmdstr = table.concat(cmd, ' ')
|
|
|
|
term({ cmd = cmdstr, autoclose = false })
|
|
|
|
return cmd
|
|
|
|
end
|
|
|
|
return M.runjob(cmd, runner, efm, args)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function handle_color(line)
|
|
|
|
if tonumber(vim.fn.match(line, '\\%x1b\\[[0-9;]\\+')) < 0 then
|
|
|
|
return line
|
|
|
|
end
|
|
|
|
if type(line) ~= 'string' then
|
|
|
|
return line
|
2022-03-23 02:40:15 +00:00
|
|
|
end
|
2023-10-31 05:30:38 +00:00
|
|
|
line = vim.fn.substitute(line, '\\%x1b\\[[0-9;]\\+[mK]', '', 'g')
|
|
|
|
log(line)
|
|
|
|
return line
|
|
|
|
end
|
|
|
|
|
|
|
|
M.runjob = function(cmd, runner, args, efm)
|
|
|
|
vim.validate({ cmd = { cmd, 't' }, runner = { runner, 's' } })
|
|
|
|
|
|
|
|
efm = efm or compile_efm()
|
2022-02-23 05:28:21 +00:00
|
|
|
local failed = false
|
2022-02-23 10:01:19 +00:00
|
|
|
local itemn = 1
|
2023-10-31 05:30:38 +00:00
|
|
|
local lines = {}
|
|
|
|
local errorlines = {}
|
|
|
|
local cmdstr = vim.fn.join(cmd, ' ') -- cmd list run without shell, cmd string run with shell
|
2022-07-07 15:27:30 +00:00
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
local package_path = (cmd[#cmd] or '')
|
2022-07-07 22:30:46 +00:00
|
|
|
if package_path ~= nil then
|
|
|
|
package_path = package_path .. util.sep()
|
2023-01-09 10:07:49 +00:00
|
|
|
if vim.fn.isdirectory(package_path) == 1 then
|
2023-09-07 08:12:43 +00:00
|
|
|
package_path = package_path .. '...'
|
2023-01-09 10:07:49 +00:00
|
|
|
else
|
2023-09-07 08:12:43 +00:00
|
|
|
package_path = ''
|
2023-01-09 10:07:49 +00:00
|
|
|
end
|
2022-07-07 22:30:46 +00:00
|
|
|
else
|
2023-09-07 08:12:43 +00:00
|
|
|
package_path = ''
|
2022-07-07 22:30:46 +00:00
|
|
|
end
|
2022-11-29 02:53:33 +00:00
|
|
|
local Sprite = util.load_plugin('guihua.lua', 'guihua.sprite')
|
|
|
|
local sprite
|
|
|
|
if Sprite then
|
|
|
|
sprite = Sprite:new({
|
|
|
|
loc = 'top_center',
|
|
|
|
syntax = 'lua',
|
2023-09-07 08:12:43 +00:00
|
|
|
rect = { height = 1, width = 30 },
|
|
|
|
data = { 'Running ' .. cmdstr },
|
2022-12-13 21:39:09 +00:00
|
|
|
timeout = 20000,
|
2022-11-29 02:53:33 +00:00
|
|
|
hl_line = 1,
|
|
|
|
})
|
|
|
|
else
|
2023-09-07 08:12:43 +00:00
|
|
|
sprite = { on_close = function() end }
|
2022-11-29 02:53:33 +00:00
|
|
|
end
|
|
|
|
|
2021-04-19 06:10:06 +00:00
|
|
|
local function on_event(job_id, data, event)
|
2022-01-11 02:50:11 +00:00
|
|
|
-- log("stdout", data, event)
|
2023-09-07 08:12:43 +00:00
|
|
|
if event == 'stdout' then
|
2021-04-19 06:10:06 +00:00
|
|
|
if data then
|
2021-12-15 08:02:22 +00:00
|
|
|
for _, value in ipairs(data) do
|
2023-09-07 08:12:43 +00:00
|
|
|
if value ~= '' then
|
|
|
|
if value:find('=== RUN') or value:find('no test file') then
|
2022-06-15 04:11:10 +00:00
|
|
|
goto continue
|
|
|
|
end
|
2022-07-07 15:27:30 +00:00
|
|
|
|
2022-01-11 02:50:11 +00:00
|
|
|
value = handle_color(value)
|
2023-09-07 08:12:43 +00:00
|
|
|
if value:find('FAIL') then
|
2022-02-23 10:01:19 +00:00
|
|
|
failed = true
|
2023-09-07 08:12:43 +00:00
|
|
|
if value == 'FAIL' then
|
2022-07-07 15:27:30 +00:00
|
|
|
goto continue
|
|
|
|
end
|
2022-02-23 10:01:19 +00:00
|
|
|
end
|
|
|
|
local changed = false
|
2023-02-01 21:53:54 +00:00
|
|
|
if vim.fn.empty(vim.fn.glob(args[#args])) == 0 then -- pkg name in args
|
2022-02-23 10:01:19 +00:00
|
|
|
changed = true
|
2023-09-07 08:12:43 +00:00
|
|
|
if value:find('FAIL') == nil then
|
2023-10-31 05:30:38 +00:00
|
|
|
local p, _, _ = extract_filepath(value, package_path)
|
2023-02-19 04:50:27 +00:00
|
|
|
if p == true then -- path existed, but need to attach the pkg name
|
|
|
|
-- log(fn, ln, package_path, package_path:gsub('%.%.%.', ''))
|
|
|
|
-- remove ... in package path
|
2023-01-11 03:53:05 +00:00
|
|
|
value = package_path:gsub('%.%.%.', '') .. util.ltrim(value)
|
2022-07-07 15:27:30 +00:00
|
|
|
end
|
2022-02-23 05:28:21 +00:00
|
|
|
end
|
2022-02-23 10:01:19 +00:00
|
|
|
else
|
2023-02-19 04:50:27 +00:00
|
|
|
local p, n = extract_filepath(value)
|
|
|
|
|
|
|
|
log(p, n, #lines)
|
|
|
|
if p == true then
|
2022-02-23 10:01:19 +00:00
|
|
|
failed = true
|
2023-09-07 08:12:43 +00:00
|
|
|
value = vim.fs.dirname(n) .. '/' .. util.ltrim(value)
|
2022-02-23 10:01:19 +00:00
|
|
|
changed = true
|
2023-02-19 04:50:27 +00:00
|
|
|
log(value)
|
2022-02-23 10:01:19 +00:00
|
|
|
end
|
2022-02-23 05:28:21 +00:00
|
|
|
end
|
2021-12-15 08:02:22 +00:00
|
|
|
table.insert(lines, value)
|
2023-10-31 05:30:38 +00:00
|
|
|
log(value, #lines)
|
2022-02-23 10:01:19 +00:00
|
|
|
if itemn == 1 and failed and changed then
|
|
|
|
itemn = #lines
|
|
|
|
end
|
2021-12-15 08:02:22 +00:00
|
|
|
end
|
2022-06-15 04:11:10 +00:00
|
|
|
::continue::
|
2021-12-15 08:02:22 +00:00
|
|
|
end
|
2021-04-19 06:10:06 +00:00
|
|
|
end
|
2023-02-20 23:16:11 +00:00
|
|
|
_GO_NVIM_CFG.on_stdout(event, data)
|
2021-04-19 06:10:06 +00:00
|
|
|
end
|
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
if event == 'stderr' then
|
2021-12-15 08:02:22 +00:00
|
|
|
if data then
|
|
|
|
for _, value in ipairs(data) do
|
2023-09-07 08:12:43 +00:00
|
|
|
if value ~= '' then
|
2021-12-15 08:02:22 +00:00
|
|
|
table.insert(errorlines, value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-09-07 08:12:43 +00:00
|
|
|
if next(errorlines) ~= nil and runner == 'golangci-lint' then
|
2022-01-11 02:50:11 +00:00
|
|
|
efm =
|
2023-09-07 08:12:43 +00:00
|
|
|
[[level=%tarning\ msg="%m:\ [%f:%l:%c:\ %.%#]",level=%tarning\ msg="%m",level=%trror\ msg="%m:\ [%f:%l:%c:\ %.%#]",level=%trror\ msg="%m",%f:%l:%c:\ %m,%f:%l:\ %m,%f:%l\ %m]]
|
2022-01-11 02:50:11 +00:00
|
|
|
end
|
2022-11-29 02:53:33 +00:00
|
|
|
|
|
|
|
sprite.on_close()
|
2023-02-20 23:16:11 +00:00
|
|
|
|
|
|
|
_GO_NVIM_CFG.on_stderr(event, data)
|
2021-12-15 08:02:22 +00:00
|
|
|
end
|
2021-12-10 10:13:23 +00:00
|
|
|
|
2023-09-07 08:12:43 +00:00
|
|
|
if event == 'exit' then
|
2023-10-31 05:30:38 +00:00
|
|
|
log('exit')
|
2022-11-29 02:53:33 +00:00
|
|
|
sprite.on_close()
|
2023-10-31 05:30:38 +00:00
|
|
|
local info = cmdstr
|
2023-02-12 20:55:00 +00:00
|
|
|
local level = vim.log.levels.INFO
|
2021-12-15 08:02:22 +00:00
|
|
|
if #errorlines > 0 then
|
|
|
|
if #lines > 0 then
|
|
|
|
vim.list_extend(errorlines, lines)
|
|
|
|
end
|
2022-07-07 15:27:30 +00:00
|
|
|
trace(errorlines)
|
2023-09-07 08:12:43 +00:00
|
|
|
vim.fn.setqflist({}, ' ', {
|
2023-10-31 05:30:38 +00:00
|
|
|
title = info,
|
2021-12-15 08:02:22 +00:00
|
|
|
lines = errorlines,
|
|
|
|
efm = efm,
|
|
|
|
})
|
2022-05-27 01:39:29 +00:00
|
|
|
failed = true
|
2022-06-01 11:29:13 +00:00
|
|
|
log(errorlines[1], job_id)
|
2023-10-31 05:30:38 +00:00
|
|
|
vim.schedule(function()
|
|
|
|
vim.cmd([[echo v:shell_error]])
|
|
|
|
end)
|
2021-12-15 08:02:22 +00:00
|
|
|
elseif #lines > 0 then
|
2022-07-07 15:27:30 +00:00
|
|
|
trace(lines)
|
2022-07-07 16:34:50 +00:00
|
|
|
local opts = {}
|
|
|
|
if _GO_NVIM_CFG.test_efm == true then
|
2023-09-07 08:12:43 +00:00
|
|
|
efm = require('go.gotest').efm()
|
2022-07-07 16:34:50 +00:00
|
|
|
opts = {
|
2023-10-31 05:30:38 +00:00
|
|
|
title = info,
|
2022-07-07 16:34:50 +00:00
|
|
|
lines = lines,
|
|
|
|
efm = efm,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
opts = {
|
2023-10-31 05:30:38 +00:00
|
|
|
title = info,
|
2022-07-07 16:34:50 +00:00
|
|
|
lines = lines,
|
|
|
|
}
|
|
|
|
end
|
2023-09-07 08:12:43 +00:00
|
|
|
vim.fn.setqflist({}, ' ', opts)
|
2021-12-15 08:02:22 +00:00
|
|
|
end
|
2021-12-16 06:46:52 +00:00
|
|
|
|
2022-05-27 01:39:29 +00:00
|
|
|
if tonumber(data) ~= 0 then
|
|
|
|
failed = true
|
2023-10-31 05:30:38 +00:00
|
|
|
info = info .. ' exited with code: ' .. tostring(data) .. vim.inspect(errorlines)
|
2023-02-12 20:55:00 +00:00
|
|
|
level = vim.log.levels.ERROR
|
2022-05-27 01:39:29 +00:00
|
|
|
end
|
2022-02-02 06:37:07 +00:00
|
|
|
_GO_NVIM_CFG.job_id = nil
|
2022-02-23 05:28:21 +00:00
|
|
|
if failed then
|
2023-10-31 05:30:38 +00:00
|
|
|
info = info .. ' go test failed'
|
2023-02-12 20:55:00 +00:00
|
|
|
level = vim.log.levels.WARN
|
2022-07-30 13:05:27 +00:00
|
|
|
util.quickfix('botright copen')
|
2022-02-23 05:28:21 +00:00
|
|
|
end
|
2022-02-23 10:01:19 +00:00
|
|
|
|
|
|
|
itemn = 1
|
2022-05-30 14:32:26 +00:00
|
|
|
if failed then
|
2023-09-07 08:12:43 +00:00
|
|
|
vim.notify(info .. ' failed', level)
|
2022-05-31 06:16:09 +00:00
|
|
|
else
|
2023-09-07 08:12:43 +00:00
|
|
|
vim.notify(info .. ' succeed', level)
|
2023-10-31 05:30:38 +00:00
|
|
|
vim.notify(table.concat(lines, '\n\r'), level)
|
2022-05-30 14:32:26 +00:00
|
|
|
end
|
2022-02-23 10:01:19 +00:00
|
|
|
failed = false
|
2023-02-20 23:16:11 +00:00
|
|
|
_GO_NVIM_CFG.on_exit(event, data)
|
2021-04-19 06:10:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-30 14:04:52 +00:00
|
|
|
-- releative dir does not work without shell
|
2023-09-07 08:12:43 +00:00
|
|
|
log('cmd ', cmdstr)
|
2023-10-31 05:30:38 +00:00
|
|
|
local runcmd = cmdstr
|
|
|
|
if is_windows then -- gitshell & cmd.exe prefer list
|
|
|
|
runcmd = cmd
|
2023-05-20 10:26:33 +00:00
|
|
|
end
|
2023-10-31 05:30:38 +00:00
|
|
|
_GO_NVIM_CFG.job_id = vim.fn.jobstart(runcmd, {
|
2021-07-08 16:16:22 +00:00
|
|
|
on_stderr = on_event,
|
|
|
|
on_stdout = on_event,
|
|
|
|
on_exit = on_event,
|
|
|
|
stdout_buffered = true,
|
2021-12-10 00:43:59 +00:00
|
|
|
stderr_buffered = true,
|
2021-07-08 16:16:22 +00:00
|
|
|
})
|
2023-10-31 05:30:38 +00:00
|
|
|
_GO_NVIM_CFG.on_jobstart(runcmd)
|
2022-05-24 07:23:53 +00:00
|
|
|
return cmd
|
2021-04-19 06:10:06 +00:00
|
|
|
end
|
|
|
|
|
2022-02-02 06:37:07 +00:00
|
|
|
M.stopjob = function(id)
|
|
|
|
id = id or _GO_NVIM_CFG.job_id
|
|
|
|
if id == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local r = vim.fn.jobstop(id)
|
|
|
|
if r == 1 then
|
|
|
|
_GO_NVIM_CFG.job_id = nil
|
|
|
|
else
|
2023-09-07 08:12:43 +00:00
|
|
|
util.warn('failed to stop job ' .. tostring(id))
|
2022-02-02 06:37:07 +00:00
|
|
|
end
|
|
|
|
end
|
2023-10-31 05:30:38 +00:00
|
|
|
M.compile_efm = compile_efm
|
2021-04-19 06:10:06 +00:00
|
|
|
return M
|