5 files changed,
40 insertions(+),
1 deletions(-)
Author:
Smirnov Olexander
ss2316544@gmail.com
Committed at:
2022-06-21 14:31:37 +0300
Parent:
572c346
M
README.md
@@ -61,6 +61,7 @@
5. Interface implementation Command syntax: + ```vim :GoImpl [receiver] [interface]@@ -69,11 +70,22 @@ :GoImpl [interface]
``` Example of usage: + ```vim " Example :GoImpl r Read io.Reader " or simply put your cursor in the struct and run: :GoImpl io.Reader +``` + +5. Run `go generate` command + +```vim +" Run `go generate` in cwd path +:GoGenerate + +" Run `go generate` for current file +:GoGenerate % ``` ## Thanks
A
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
M
lua/gopher/health.lua
@@ -6,7 +6,7 @@ { lib = "plenary" },
{ 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" }, },
M
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
M
plugin/gopher.vim
@@ -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()