diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index 1b8f91c..0f9db8b 100644 --- a/lua/gopher/config.lua +++ b/lua/gopher/config.lua @@ -93,10 +93,17 @@ function config.setup(user_config) _config = vim.tbl_deep_extend("force", default_config, user_config or {}) end +---@return boolean +---@private +function config.should_setup_commands() + return config.setup_commands +end + setmetatable(config, { __index = function(_, key) return _config[key] end, }) +---@return gopher.Config return config diff --git a/plugin/gopher.lua b/plugin/gopher.lua index 2429b25..a813bb4 100644 --- a/plugin/gopher.lua +++ b/plugin/gopher.lua @@ -3,74 +3,77 @@ if vim.g.gopher_loaded == 1 then end vim.g.gopher_loaded = 1 -local c = require "gopher.config" -if c.setup_commands then - vim.api.nvim_create_user_command("GopherLog", function() - vim.cmd("tabnew " .. require("gopher._utils.log").get_outfile()) - end, { nargs = 0 }) +--- NOTE: runs in defer since this file before gopher.config +--- I'm not sure if this is the best to do this +vim.defer_fn(function() + if require("gopher.config").should_setup_commands() then + vim.api.nvim_create_user_command("GopherLog", function() + vim.cmd("tabnew " .. require("gopher._utils.log").get_outfile()) + end, { nargs = 0 }) - vim.api.nvim_create_user_command("GoIfErr", function() - require("gopher").iferr() - end, { nargs = 0 }) + vim.api.nvim_create_user_command("GoIfErr", function() + require("gopher").iferr() + end, { nargs = 0 }) - vim.api.nvim_create_user_command("GoCmt", function() - require("gopher").comment() - end, { nargs = 0 }) + vim.api.nvim_create_user_command("GoCmt", function() + require("gopher").comment() + end, { nargs = 0 }) - vim.api.nvim_create_user_command("GoImpl", function(args) - require("gopher").impl(unpack(args.fargs)) - end, { nargs = "*" }) + vim.api.nvim_create_user_command("GoImpl", function(args) + require("gopher").impl(unpack(args.fargs)) + end, { nargs = "*" }) - -- :GoInstall - vim.api.nvim_create_user_command("GoInstallDeps", function() - require("gopher").install_deps() - end, { nargs = 0 }) + -- :GoInstall + vim.api.nvim_create_user_command("GoInstallDeps", function() + require("gopher").install_deps() + end, { nargs = 0 }) - vim.api.nvim_create_user_command("GoInstallDepsSync", function() - require("gopher").install_deps { sync = true } - end, { nargs = 0 }) + vim.api.nvim_create_user_command("GoInstallDepsSync", function() + require("gopher").install_deps { sync = true } + end, { nargs = 0 }) - --- :GoTag - vim.api.nvim_create_user_command("GoTagAdd", function(opts) - require("gopher").tags.add(unpack(opts.fargs)) - end, { nargs = "*" }) + --- :GoTag + vim.api.nvim_create_user_command("GoTagAdd", function(opts) + require("gopher").tags.add(unpack(opts.fargs)) + end, { nargs = "*" }) - vim.api.nvim_create_user_command("GoTagRm", function(opts) - require("gopher").tags.rm(unpack(opts.fargs)) - end, { nargs = "*" }) + vim.api.nvim_create_user_command("GoTagRm", function(opts) + require("gopher").tags.rm(unpack(opts.fargs)) + end, { nargs = "*" }) - vim.api.nvim_create_user_command("GoTagClear", function() - require("gopher").tags.clear() - end, { nargs = 0 }) + vim.api.nvim_create_user_command("GoTagClear", function() + require("gopher").tags.clear() + end, { nargs = 0 }) - --- :GoTest - vim.api.nvim_create_user_command("GoTestAdd", function() - require("gopher").test.add() - end, { nargs = 0 }) + --- :GoTest + vim.api.nvim_create_user_command("GoTestAdd", function() + require("gopher").test.add() + end, { nargs = 0 }) - vim.api.nvim_create_user_command("GoTestsAll", function() - require("gopher").test.all() - end, { nargs = 0 }) + vim.api.nvim_create_user_command("GoTestsAll", function() + require("gopher").test.all() + end, { nargs = 0 }) - vim.api.nvim_create_user_command("GoTestsExp", function() - require("gopher").test.exported() - end, { nargs = 0 }) + vim.api.nvim_create_user_command("GoTestsExp", function() + require("gopher").test.exported() + end, { nargs = 0 }) - -- :Go - vim.api.nvim_create_user_command("GoMod", function(opts) - require("gopher").mod(opts.fargs) - end, { nargs = "*" }) + -- :Go + vim.api.nvim_create_user_command("GoMod", function(opts) + require("gopher").mod(opts.fargs) + end, { nargs = "*" }) - vim.api.nvim_create_user_command("GoGet", function(opts) - vim.print(opts) - require("gopher").get(opts.fargs) - end, { nargs = "*" }) + vim.api.nvim_create_user_command("GoGet", function(opts) + vim.print(opts) + require("gopher").get(opts.fargs) + end, { nargs = "*" }) - vim.api.nvim_create_user_command("GoWork", function(opts) - require("gopher").get(opts.fargs) - end, { nargs = "*" }) + vim.api.nvim_create_user_command("GoWork", function(opts) + require("gopher").get(opts.fargs) + end, { nargs = "*" }) - vim.api.nvim_create_user_command("GoGenerate", function(opts) - require("gopher").generate(opts.fargs or "") - end, { nargs = "?" }) -end + vim.api.nvim_create_user_command("GoGenerate", function(opts) + require("gopher").generate(opts.fargs or "") + end, { nargs = "?" }) + end +end, 0)