feat: add GoGenerate command
feat(health): add gogenerate docs(gogenerate): add doc
This commit is contained in:
parent
572c346098
commit
507ccb6347
5 changed files with 40 additions and 1 deletions
12
README.md
12
README.md
|
|
@ -61,6 +61,7 @@ You can provide more that one package url.
|
|||
5. Interface implementation
|
||||
|
||||
Command syntax:
|
||||
|
||||
```vim
|
||||
:GoImpl [receiver] [interface]
|
||||
|
||||
|
|
@ -69,6 +70,7 @@ Command syntax:
|
|||
```
|
||||
|
||||
Example of usage:
|
||||
|
||||
```vim
|
||||
" Example
|
||||
:GoImpl r Read io.Reader
|
||||
|
|
@ -76,6 +78,16 @@ Example of usage:
|
|||
:GoImpl io.Reader
|
||||
```
|
||||
|
||||
5. Run `go generate` command
|
||||
|
||||
```vim
|
||||
" Run `go generate` in cwd path
|
||||
:GoGenerate
|
||||
|
||||
" Run `go generate` for current file
|
||||
:GoGenerate %
|
||||
```
|
||||
|
||||
## Thanks
|
||||
|
||||
- [go.nvim](https://github.com/ray-x/go.nvim)
|
||||
|
|
|
|||
25
lua/gopher/gogenerate.lua
Normal file
25
lua/gopher/gogenerate.lua
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
local Job = require "plenary.job"
|
||||
|
||||
return function(...)
|
||||
local args = { ... }
|
||||
if #args == 1 and args[1] == "%" then
|
||||
args[1] = vim.fn.expand "%" ---@diagnostic disable-line: missing-parameter
|
||||
end
|
||||
|
||||
local cmd_args = vim.list_extend({ "generate" }, args)
|
||||
|
||||
Job
|
||||
:new({
|
||||
command = "go",
|
||||
args = cmd_args,
|
||||
on_exit = function(_, retval)
|
||||
if retval ~= 0 then
|
||||
print("command exited with code " .. retval)
|
||||
return
|
||||
else
|
||||
print "command runs successfully"
|
||||
end
|
||||
end,
|
||||
})
|
||||
:start()
|
||||
end
|
||||
|
|
@ -6,7 +6,7 @@ local M = {
|
|||
{ lib = "nvim-treesitter" },
|
||||
},
|
||||
binarys = {
|
||||
{ bin = "go", help = "required for GoMod command" },
|
||||
{ bin = "go", help = "required for GoMod, GoGet, GoGenerate command" },
|
||||
{ bin = "gomodifytags", help = "required for modify struct tags" },
|
||||
{ bin = "impl", help = "required for interface implementing" },
|
||||
},
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ gopher.tags_rm = tags.remove
|
|||
gopher.mod = require "gopher.gomod"
|
||||
gopher.get = require "gopher.goget"
|
||||
gopher.impl = require "gopher.impl"
|
||||
gopher.generate = require "gopher.gogenerate"
|
||||
|
||||
return gopher
|
||||
|
|
|
|||
|
|
@ -3,4 +3,5 @@ command! -nargs=* GoTagRm :lua require"gopher".tags_rm(<f-args>)
|
|||
command! -nargs=* GoMod :lua require"gopher".mod(<f-args>)
|
||||
command! -nargs=* GoGet :lua require"gopher".get(<f-args>)
|
||||
command! -nargs=* GoImpl :lua require"gopher".impl(<f-args>)
|
||||
command! -nargs=* GoGenerate :lua require"gopher".generate(<f-args>)
|
||||
command! GoInstallDeps :lua require"gopher".install_deps()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue