-
-
Notifications
You must be signed in to change notification settings - Fork 306
fix: #657 don't show error message for optional integrations #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9f9b8da
8053197
960f57c
e09dd40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous auto integration relies on the metatable being left intact and would break if the table was replaced. Additionally, this makes the config data only and does not muddle printing or probing of the config with runtime determined fields or obscuring what the user originally said with what we found through pcall. This functionality is now ensured by the |
||
| 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 | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of a boolean param, can we do an opts table, like
{ required = x }? Not a huge fan of naked boolean params. Thats how you wind up with a function signature likecall("string", true, false, true true):PThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Not entirely sure about the existing name for the function either.
ensure_, at least the way I've encountered and used the name refers to a function which does a check and in some way ensures a value, such as generating one if it doesn't exist, ensures a column is present in a database etc.This is essentially a query or check function, especially when adding a
{ required = true }Perhaps
query_integration(name) -> booland the have the caller do an error or fallback, with better context, such asdiffview integration needs to be enabled for "diff head"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of leaving it up to the caller. That removes the need for the
{ required = true }param altogether, and... wait for it... we could call it...check_integration(name). Because it's a check.. for the integration. :PThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Often great solutions come from stepping back and looking at the larger picture, rather than adding yet another bool argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change to check and provided some more descriptive error messages that show a notification.
Just fixed a
call("string", true, false, true true)situation where a big async function begun with an if statement, that either allocated a scratch buffer and did a thing, or did a thing directly. Just pried it apart into two functions, as the bools were never dynamic but always hardcoded anywayThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeahhh. Thats something I remember from.. I think Uncle Bob... early on in my career. If you are controlling a functions behaviour externally with boolean flags... congrats, you have two functions :P