fix(plugin): respect setup_commands option

This commit is contained in:
Oleksandr Smirnov 2025-03-21 16:51:30 +02:00
parent b49175cd34
commit eeff227715
No known key found for this signature in database
2 changed files with 66 additions and 56 deletions

View file

@ -93,10 +93,17 @@ function config.setup(user_config)
_config = vim.tbl_deep_extend("force", default_config, user_config or {}) _config = vim.tbl_deep_extend("force", default_config, user_config or {})
end end
---@return boolean
---@private
function config.should_setup_commands()
return config.setup_commands
end
setmetatable(config, { setmetatable(config, {
__index = function(_, key) __index = function(_, key)
return _config[key] return _config[key]
end, end,
}) })
---@return gopher.Config
return config return config

View file

@ -3,8 +3,10 @@ if vim.g.gopher_loaded == 1 then
end end
vim.g.gopher_loaded = 1 vim.g.gopher_loaded = 1
local c = require "gopher.config" --- NOTE: runs in defer since this file before gopher.config
if c.setup_commands then --- 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.api.nvim_create_user_command("GopherLog", function()
vim.cmd("tabnew " .. require("gopher._utils.log").get_outfile()) vim.cmd("tabnew " .. require("gopher._utils.log").get_outfile())
end, { nargs = 0 }) end, { nargs = 0 })
@ -74,3 +76,4 @@ if c.setup_commands then
require("gopher").generate(opts.fargs or "") require("gopher").generate(opts.fargs or "")
end, { nargs = "?" }) end, { nargs = "?" })
end end
end, 0)