[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang
at main 2.2 kB view raw
1---@toc_entry Commands 2---@tag gopher.nvim-commands 3---@text 4--- If don't want to automatically register plugins' commands, 5--- you can set `vim.g.gopher_register_commands` to `false`, before loading the plugin. 6 7if vim.g.gopher_register_commands == false then 8 return 9end 10 11---@param name string 12---@param fn fun(args: table) 13---@param nargs? number|"*"|"?" 14---@param range? boolean 15---@private 16local function cmd(name, fn, nargs, range) 17 vim.api.nvim_create_user_command(name, fn, { 18 nargs = nargs or 0, 19 range = range or false, 20 }) 21end 22 23cmd("GopherLog", function() 24 vim.cmd("tabnew " .. require("gopher._utils.log").get_outfile()) 25end) 26 27cmd("GoIfErr", function() 28 require("gopher").iferr() 29end) 30 31cmd("GoCmt", function() 32 require("gopher").comment() 33end) 34 35cmd("GoImpl", function(args) 36 require("gopher").impl(unpack(args.fargs)) 37end, "*") 38 39-- :GoInstall 40cmd("GoInstallDeps", function() 41 require("gopher").install_deps() 42end) 43 44cmd("GoInstallDepsSync", function() 45 require("gopher").install_deps { sync = true } 46end) 47 48-- :GoTag 49cmd("GoTagAdd", function(opts) 50 require("gopher").tags.add { 51 input = opts.fargs, 52 range = (opts.count ~= -1) and { 53 start = opts.line1, 54 end_ = opts.line2, 55 } or nil, 56 } 57end, "*", true) 58 59cmd("GoTagRm", function(opts) 60 require("gopher").tags.rm { 61 input = opts.fargs, 62 range = (opts.count ~= -1) and { 63 start = opts.line1, 64 end_ = opts.line2, 65 } or nil, 66 } 67end, "*", true) 68 69cmd("GoTagClear", function() 70 require("gopher").tags.clear() 71end) 72 73-- :GoJson 74cmd("GoJson", function(opts) 75 local inp = ((opts.args ~= "" and opts.args) or nil) 76 require("gopher.json2go").json2go(inp) 77end, "*") 78 79-- :GoTest 80cmd("GoTestAdd", function() 81 require("gopher").test.add() 82end) 83 84cmd("GoTestsAll", function() 85 require("gopher").test.all() 86end) 87 88cmd("GoTestsExp", function() 89 require("gopher").test.exported() 90end) 91 92-- :Go 93cmd("GoMod", function(opts) 94 require("gopher").mod(opts.fargs) 95end, "*") 96 97cmd("GoGet", function(opts) 98 require("gopher").get(opts.fargs) 99end, "*") 100 101cmd("GoWork", function(opts) 102 require("gopher").get(opts.fargs) 103end, "*") 104 105cmd("GoGenerate", function(opts) 106 require("gopher").generate(opts.fargs or { "" }) 107end, "?")