[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 108 lines 2.3 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(opts) 28 local msg = ((opts.args ~= "" and opts.args) or nil) 29 require("gopher").iferr(msg) 30end, "*") 31 32cmd("GoCmt", function() 33 require("gopher").comment() 34end) 35 36cmd("GoImpl", function(args) 37 require("gopher").impl(unpack(args.fargs)) 38end, "*") 39 40-- :GoInstall 41cmd("GoInstallDeps", function() 42 require("gopher").install_deps() 43end) 44 45cmd("GoInstallDepsSync", function() 46 require("gopher").install_deps { sync = true } 47end) 48 49-- :GoTag 50cmd("GoTagAdd", function(opts) 51 require("gopher").tags.add { 52 input = opts.fargs, 53 range = (opts.count ~= -1) and { 54 start = opts.line1, 55 end_ = opts.line2, 56 } or nil, 57 } 58end, "*", true) 59 60cmd("GoTagRm", function(opts) 61 require("gopher").tags.rm { 62 input = opts.fargs, 63 range = (opts.count ~= -1) and { 64 start = opts.line1, 65 end_ = opts.line2, 66 } or nil, 67 } 68end, "*", true) 69 70cmd("GoTagClear", function() 71 require("gopher").tags.clear() 72end) 73 74-- :GoJson 75cmd("GoJson", function(opts) 76 local inp = ((opts.args ~= "" and opts.args) or nil) 77 require("gopher.json2go").json2go(inp) 78end, "*") 79 80-- :GoTest 81cmd("GoTestAdd", function() 82 require("gopher").test.add() 83end) 84 85cmd("GoTestsAll", function() 86 require("gopher").test.all() 87end) 88 89cmd("GoTestsExp", function() 90 require("gopher").test.exported() 91end) 92 93-- :Go 94cmd("GoMod", function(opts) 95 require("gopher").mod(opts.fargs) 96end, "*") 97 98cmd("GoGet", function(opts) 99 require("gopher").get(opts.fargs) 100end, "*") 101 102cmd("GoWork", function(opts) 103 require("gopher").get(opts.fargs) 104end, "*") 105 106cmd("GoGenerate", function(opts) 107 require("gopher").generate(opts.fargs or { "" }) 108end, "?")