Allow on_stdout/exit/stderr hooks so the jobs can be pipelined

This commit is contained in:
ray-x 2023-02-21 10:16:11 +11:00
parent 0f0b8fe795
commit 2ed66cb302
4 changed files with 30 additions and 2 deletions

View File

@ -30,8 +30,8 @@ The plugin covers most features required for a gopher.
- Smart build tag detection when debug/run tests (e.g. `//go:build integration`)
- Generate mocks with mockgen
- Inlay hints: gopls (version 0.9.x or greater) inlay hints
- luasnip: you might use friendly-snippets already, you still need to try pure lua snippets with go.nvim out,
checkout [LuaSnip Tutorial](https://www.youtube.com/watch?v=ub0REXjhpmk) and [TJ's Introduction to LuaSnip](https://www.youtube.com/watch?v=Dn800rlPIho)
- luasnip: go.nvim included a feature rich luasnips you definitally need to try.
If you are not familiar with luasnip, please checkout [LuaSnip Tutorial](https://www.youtube.com/watch?v=ub0REXjhpmk) and [TJ's Introduction to LuaSnip](https://www.youtube.com/watch?v=Dn800rlPIho)
## Installation
@ -793,6 +793,10 @@ require('go').setup({
test_efm = false, -- errorfomat for quickfix, default mix mode, set to true will be efm only
luasnip = false, -- enable included luasnip snippets. you can also disable while add lua/snips folder to luasnip load
-- Do not enable this if you already added the path, that will duplicate the entries
on_jobstart = function(cmd) _=cmd end, -- callback for stdout
on_stdout = function(err, data) _, _ = err, data end, -- callback when job started
on_stderr = function(err, data) _, _ = err, data end, -- callback for stderr
on_exit = function(code, signal, output) _, _, _ = code, signal, output end, -- callback for jobexit, output : string
})
```
@ -928,6 +932,15 @@ My treesitter config:
}
```
## LuaSnip supports
go.nvim provides a better snippet support for go.
Please check [snippets for all languages](https://github.com/ray-x/go.nvim/blob/master/lua/snips/all.lua)
and [snippets for go](https://github.com/ray-x/go.nvim/blob/master/lua/snips/go.lua)
For a video demo, please check this:
[go.nvim new features work through](https://www.youtube.com/watch?v=tsLnEfYTgcM)
## Nvim LSP setup
go.nvim provided a better non-default setup for gopls (includes debounce, staticcheck, diagnosticsDelay etc)

View File

@ -124,6 +124,10 @@ _GO_NVIM_CFG = {
username = '',
useremail = '',
disable_per_project_cfg = false, -- set to true to disable load script from .gonvim/init.lua
on_jobstart = function(cmd) _=cmd end, -- callback for stdout
on_stdout = function(err, data) _, _ = err, data end, -- callback when job started
on_stderr = function(err, data) _, _ = err, data end, -- callback for stderr
on_exit = function(code, signal, output) _, _, _ = code, signal, output end, -- callback for jobexit, output : string
}
-- TODO: nvim_{add,del}_user_command https://github.com/neovim/neovim/pull/16752

View File

@ -267,6 +267,7 @@ function M.make(...)
::continue::
end
end
_GO_NVIM_CFG.on_stdout(event, data)
end
if event == "stderr" then
@ -283,6 +284,8 @@ function M.make(...)
end
sprite.on_close()
_GO_NVIM_CFG.on_stderr(event, data)
end
if event == "exit" then
@ -343,6 +346,8 @@ function M.make(...)
vim.notify(info .. " succeed", level)
end
failed = false
_GO_NVIM_CFG.on_exit(event, data)
end
end
@ -355,6 +360,7 @@ function M.make(...)
stdout_buffered = true,
stderr_buffered = true,
})
_GO_NVIM_CFG.on_jobstart(cmdstr)
return cmd
end

View File

@ -75,6 +75,7 @@ local run = function(cmd, opts)
if opts.on_chunk and lines then
opts.on_chunk(err, lines)
end
_GO_NVIM_CFG.on_stdout(err, chunk)
end
log('job:', cmd, job_options)
@ -149,8 +150,11 @@ local run = function(cmd, opts)
end)
end
end
_GO_NVIM_CFG.on_exit(code, signal, output_buf)
end
)
_GO_NVIM_CFG.on_jobstart(cmd)
uv.read_start(stderr, function(err, data)
if err then
@ -160,6 +164,7 @@ local run = function(cmd, opts)
log(data)
output_stderr = output_stderr .. tostring(data)
end
_GO_NVIM_CFG.on_stderr(err, data)
end)
stdout:read_start(update_chunk)
return stdin, stdout, stderr