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

fix!: fix "Command X not found after loading gopher.nvim" (#100)

BREAKING CHANGE: now calling .setup is required

authored by olexsmir.xyz and committed by olexsmir.xyz acd4e6fc 969db908

verified
Changed files
+87 -75
lua
plugin
+1 -1
README.md
··· 29 29 vim.cmd.GoInstallDeps() 30 30 end, 31 31 ---@type gopher.Config 32 - opts = {}, 32 + opts = {}, -- required 33 33 } 34 34 ``` 35 35
+82
lua/gopher/commands.lua
··· 1 + local commands = {} 2 + 3 + ---@param name string 4 + ---@param fn fun(args: table) 5 + ---@param nargs? number|"*"|"?" 6 + local function cmd(name, fn, nargs) 7 + nargs = nargs or 0 8 + vim.api.nvim_create_user_command(name, fn, { nargs = nargs }) 9 + end 10 + 11 + function commands.register() 12 + cmd("GopherLog", function() 13 + vim.cmd("tabnew " .. require("gopher._utils.log").get_outfile()) 14 + end) 15 + 16 + cmd("GoIfErr", function() 17 + require("gopher").iferr() 18 + end) 19 + 20 + cmd("GoCmt", function() 21 + require("gopher").comment() 22 + end) 23 + 24 + cmd("GoImpl", function(args) 25 + require("gopher").impl(unpack(args.fargs)) 26 + end, "*") 27 + 28 + -- :GoInstall 29 + cmd("GoInstallDeps", function() 30 + require("gopher").install_deps() 31 + end) 32 + 33 + cmd("GoInstallDepsSync", function() 34 + require("gopher").install_deps { sync = true } 35 + end) 36 + 37 + --- :GoTag 38 + cmd("GoTagAdd", function(opts) 39 + require("gopher").tags.add(unpack(opts.fargs)) 40 + end, "*") 41 + 42 + cmd("GoTagRm", function(opts) 43 + require("gopher").tags.rm(unpack(opts.fargs)) 44 + end, "*") 45 + 46 + cmd("GoTagClear", function() 47 + require("gopher").tags.clear() 48 + end) 49 + 50 + --- :GoTest 51 + cmd("GoTestAdd", function() 52 + require("gopher").test.add() 53 + end) 54 + 55 + cmd("GoTestsAll", function() 56 + require("gopher").test.all() 57 + end) 58 + 59 + cmd("GoTestsExp", function() 60 + require("gopher").test.exported() 61 + end) 62 + 63 + -- :Go 64 + cmd("GoMod", function(opts) 65 + require("gopher").mod(opts.fargs) 66 + end, "*") 67 + 68 + cmd("GoGet", function(opts) 69 + vim.print(opts) 70 + require("gopher").get(opts.fargs) 71 + end, "*") 72 + 73 + cmd("GoWork", function(opts) 74 + require("gopher").get(opts.fargs) 75 + end, "*") 76 + 77 + cmd("GoGenerate", function(opts) 78 + require("gopher").generate(opts.fargs or "") 79 + end, "?") 80 + end 81 + 82 + return commands
+4
lua/gopher/config.lua
··· 114 114 ["iferr"] = { _config.iferr, "table" }, 115 115 ["iferr.message"] = { _config.iferr.message, "string", true }, 116 116 } 117 + 118 + if _config.setup_commands then 119 + require("gopher.commands").register() 120 + end 117 121 end 118 122 119 123 ---@return boolean
-74
plugin/gopher.lua
··· 1 - --- NOTE: runs in defer since this file before gopher.config 2 - --- I'm not sure if this is the best to do this 3 - vim.schedule(function() 4 - if require("gopher.config").should_setup_commands() then 5 - vim.api.nvim_create_user_command("GopherLog", function() 6 - vim.cmd("tabnew " .. require("gopher._utils.log").get_outfile()) 7 - end, { nargs = 0 }) 8 - 9 - vim.api.nvim_create_user_command("GoIfErr", function() 10 - require("gopher").iferr() 11 - end, { nargs = 0 }) 12 - 13 - vim.api.nvim_create_user_command("GoCmt", function() 14 - require("gopher").comment() 15 - end, { nargs = 0 }) 16 - 17 - vim.api.nvim_create_user_command("GoImpl", function(args) 18 - require("gopher").impl(unpack(args.fargs)) 19 - end, { nargs = "*" }) 20 - 21 - -- :GoInstall 22 - vim.api.nvim_create_user_command("GoInstallDeps", function() 23 - require("gopher").install_deps() 24 - end, { nargs = 0 }) 25 - 26 - vim.api.nvim_create_user_command("GoInstallDepsSync", function() 27 - require("gopher").install_deps { sync = true } 28 - end, { nargs = 0 }) 29 - 30 - --- :GoTag 31 - vim.api.nvim_create_user_command("GoTagAdd", function(opts) 32 - require("gopher").tags.add(unpack(opts.fargs)) 33 - end, { nargs = "*" }) 34 - 35 - vim.api.nvim_create_user_command("GoTagRm", function(opts) 36 - require("gopher").tags.rm(unpack(opts.fargs)) 37 - end, { nargs = "*" }) 38 - 39 - vim.api.nvim_create_user_command("GoTagClear", function() 40 - require("gopher").tags.clear() 41 - end, { nargs = 0 }) 42 - 43 - --- :GoTest 44 - vim.api.nvim_create_user_command("GoTestAdd", function() 45 - require("gopher").test.add() 46 - end, { nargs = 0 }) 47 - 48 - vim.api.nvim_create_user_command("GoTestsAll", function() 49 - require("gopher").test.all() 50 - end, { nargs = 0 }) 51 - 52 - vim.api.nvim_create_user_command("GoTestsExp", function() 53 - require("gopher").test.exported() 54 - end, { nargs = 0 }) 55 - 56 - -- :Go 57 - vim.api.nvim_create_user_command("GoMod", function(opts) 58 - require("gopher").mod(opts.fargs) 59 - end, { nargs = "*" }) 60 - 61 - vim.api.nvim_create_user_command("GoGet", function(opts) 62 - vim.print(opts) 63 - require("gopher").get(opts.fargs) 64 - end, { nargs = "*" }) 65 - 66 - vim.api.nvim_create_user_command("GoWork", function(opts) 67 - require("gopher").get(opts.fargs) 68 - end, { nargs = "*" }) 69 - 70 - vim.api.nvim_create_user_command("GoGenerate", function(opts) 71 - require("gopher").generate(opts.fargs or "") 72 - end, { nargs = "?" }) 73 - end 74 - end)