diff --git a/README.md b/README.md index c48dcfc..058f9b8 100644 --- a/README.md +++ b/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) diff --git a/lua/gopher/gogenerate.lua b/lua/gopher/gogenerate.lua new file mode 100644 index 0000000..78d6e45 --- /dev/null +++ b/lua/gopher/gogenerate.lua @@ -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 diff --git a/lua/gopher/health.lua b/lua/gopher/health.lua index 691a1ca..72de74d 100644 --- a/lua/gopher/health.lua +++ b/lua/gopher/health.lua @@ -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" }, }, diff --git a/lua/gopher/init.lua b/lua/gopher/init.lua index 3af5005..dddb7f2 100644 --- a/lua/gopher/init.lua +++ b/lua/gopher/init.lua @@ -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 diff --git a/plugin/gopher.vim b/plugin/gopher.vim index caeeb80..6e1224f 100644 --- a/plugin/gopher.vim +++ b/plugin/gopher.vim @@ -3,4 +3,5 @@ command! -nargs=* GoTagRm :lua require"gopher".tags_rm() command! -nargs=* GoMod :lua require"gopher".mod() command! -nargs=* GoGet :lua require"gopher".get() command! -nargs=* GoImpl :lua require"gopher".impl() +command! -nargs=* GoGenerate :lua require"gopher".generate() command! GoInstallDeps :lua require"gopher".install_deps()