Add GoStop command to stop the background task started with GoRun

pull/87/head
ray-x 2 years ago
parent 2b059afc54
commit edbd796ded

@ -187,6 +187,7 @@ first run of `GoFmt` may fail. It is recommended to run `GoInstallBinaries` to i
| GoBuild | |
| GoGenerate | |
| GoRun | e.g. GoRun equal to `go run .`; or `GoRun ./cmd` equal to `go run ./cmd` |
| GoStop {job_id} | `stop the job started with GoRun |
| GoTest | go test ./... |
| GoTest -c | go test -c current_file_path |
| GoTest -tags=yourtags | go test ./... -tags=yourtags |

@ -170,6 +170,11 @@ COMMANDS *go-nvim-commands*
:GoBuild {-tags=tagname}{pakcage_name} *:GoBuild*
Build current package
:GoRun {-tags=tagname} *:GoRun*
equal to "go run ."
:GoStop *:GoStop*
stop the task started with GoRun
:GoTest {-c} {-tags=tagname} {pakcage_name} *:GoTest*
-c: compile test in current package
-tags: compile tag

@ -94,6 +94,8 @@ function go.setup(cfg)
gobin
)
vim.cmd(cmd)
vim.cmd([[command! -nargs=* GoStop lua require("go.asyncmake").stopjob(<f-args>)]])
-- if you want to output to quickfix
-- vim.cmd(
-- [[command! -nargs=* GoTest :setl makeprg=go\ test\ -v\ ./...| lua require'go.asyncmake'.make(<f-args>)]])

@ -146,8 +146,8 @@ function M.make(...)
efm = efm,
})
vim.api.nvim_command("doautocmd QuickFixCmdPost")
vim.cmd("botright copen")
vim.api.nvim_command("doautocmd QuickFixCmdPost")
vim.cmd("botright copen")
elseif #lines > 0 then
vim.fn.setqflist({}, " ", {
title = cmd,
@ -159,11 +159,12 @@ function M.make(...)
cmd = table.concat(cmd, " ")
end
vim.notify(cmd .. " finished", vim.lsp.log_levels.WARN)
_GO_NVIM_CFG.job_id = nil
end
end
log("cmd ", cmd)
local job_id = vim.fn.jobstart(cmd, {
_GO_NVIM_CFG.job_id = vim.fn.jobstart(cmd, {
on_stderr = on_event,
on_stdout = on_event,
on_exit = on_event,
@ -172,4 +173,17 @@ function M.make(...)
})
end
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
util.warn("failed to stop job " .. tostring(id))
end
end
return M

Loading…
Cancel
Save