diff --git a/README.md b/README.md index 6afafec50..faa7cd7fe 100644 --- a/README.md +++ b/README.md @@ -175,11 +175,11 @@ neogit.setup { item = { ">", "v" }, hunk = { "", "" }, }, - -- Integrations are auto-detected, and enabled if available, but can be disabled by setting to "false" + -- Each Integration is auto-detected through plugin presence. Disabled by setting to `false` integrations = { -- If enabled, use telescope for menu selection rather than vim.ui.select. -- Allows multi-select and some things that vim.ui.select doesn't. - telescope = false, + telescope = nil, -- Neogit only provides inline diffs. If you want a more traditional way to look at diffs, you can use `sindrets/diffview.nvim`. -- The diffview integration enables the diff popup, which is a wrapper around `sindrets/diffview.nvim`. @@ -193,7 +193,7 @@ neogit.setup { -- } -- } -- - diffview = false, + diffview = nil, }, -- Setting any section to `false` will make the section not render at all sections = { diff --git a/lua/neogit/buffers/log_view/init.lua b/lua/neogit/buffers/log_view/init.lua index 300009b50..bcdafcd1e 100644 --- a/lua/neogit/buffers/log_view/init.lua +++ b/lua/neogit/buffers/log_view/init.lua @@ -122,8 +122,10 @@ function M:open() end end, ["d"] = function() - if not config.ensure_integration("diffview") then - return + if not config.check_integration("diffview") then + require("neogit.lib.notification").create_error( + "Diffview integration must be enabled for log diff" + ) end local stack = self.buffer.ui:get_component_stack_under_cursor() diff --git a/lua/neogit/buffers/reflog_view/init.lua b/lua/neogit/buffers/reflog_view/init.lua index 63cfbe65b..e90525e2a 100644 --- a/lua/neogit/buffers/reflog_view/init.lua +++ b/lua/neogit/buffers/reflog_view/init.lua @@ -84,7 +84,10 @@ function M:open() CommitViewBuffer.new(stack[#stack].options.oid):open() end, ["d"] = function() - if not config.ensure_integration("diffview") then + if not config.check_integration("diffview") then + require("neogit.lib.notification").create_error( + "Diffview integration must be enabled for reflog diff" + ) return end diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index d7c23b9ce..9eaeafc0d 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -59,12 +59,10 @@ M.values = { item = { ">", "v" }, section = { ">", "v" }, }, - integrations = setmetatable({}, { - __index = function(_, key) - local ok, value = pcall(require, key) - return ok and value or false - end, - }), + integrations = { + telescope = nil, + diffview = nil, + }, sections = { untracked = { folded = false, @@ -153,13 +151,20 @@ M.values = { }, } -function M.ensure_integration(name) - if not M.values.integrations[name] then - vim.api.nvim_err_writeln(string.format("Neogit: `%s` integration is not enabled", name)) - return false +---@param name string +---@return boolean +function M.check_integration(name) + local logger = require("neogit.logger") + local enabled = M.values.integrations[name] + + if enabled == nil or enabled == "auto" then + local success, _ = pcall(require, name) + logger.fmt_info("[CONFIG] Found auto integration '%s = %s'", name, success) + return success end - return true + logger.fmt_info("[CONFIG] Found explicit integration '%s' = %s", name, enabled) + return enabled end return M diff --git a/lua/neogit/lib/finder.lua b/lua/neogit/lib/finder.lua index 0ad533a96..6fa3473f6 100644 --- a/lua/neogit/lib/finder.lua +++ b/lua/neogit/lib/finder.lua @@ -122,7 +122,7 @@ end ---Engages finder and invokes `on_select` with the item or items, or nil if aborted ---@param on_select fun(item: any|nil) function Finder:find(on_select) - if config.ensure_integration("telescope") then + if config.check_integration("telescope") then local pickers = require("telescope.pickers") local finders = require("telescope.finders") local sorters = require("telescope.sorters") diff --git a/lua/neogit/lib/notification.lua b/lua/neogit/lib/notification.lua index c521cf125..89a615a98 100644 --- a/lua/neogit/lib/notification.lua +++ b/lua/neogit/lib/notification.lua @@ -147,6 +147,9 @@ end return { create = create, + error = function(msg, delay) + return create(msg, vim.log.levels.ERROR, delay) + end, delete_all = function() for _, n in ipairs(notifications) do n:delete() diff --git a/lua/neogit/popups/diff/init.lua b/lua/neogit/popups/diff/init.lua index 9df412593..31cd78058 100644 --- a/lua/neogit/popups/diff/init.lua +++ b/lua/neogit/popups/diff/init.lua @@ -4,7 +4,8 @@ local config = require("neogit.config") local popup = require("neogit.lib.popup") function M.create() - if not config.ensure_integration("diffview") then + if not config.check_integration("diffview") then + require("neogit.lib.notification").create_error("Diffview integration must be enabled for diff popup") return end diff --git a/lua/neogit/status.lua b/lua/neogit/status.lua index 84129c69e..a8491926b 100644 --- a/lua/neogit/status.lua +++ b/lua/neogit/status.lua @@ -1030,9 +1030,11 @@ local cmd_func_map = function() -- INTEGRATIONS -- ["DiffAtFile"] = function() - if not config.ensure_integration("diffview") then + if not config.check_integration("diffview") then + require("neogit.lib.notification").error("Diffview integration is not enabled") return end + local dv = require("neogit.integrations.diffview") local section, item = get_current_section_item()