Skip to content

Conversation

@ten3roberts
Copy link
Member

No description provided.

end
end,
["d"] = function()
if not config.ensure_integration("diffview") then
Copy link
Member

@CKolkey CKolkey Jul 21, 2023

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 like call("string", true, false, true true) :P

Copy link
Member Author

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) -> bool and the have the caller do an error or fallback, with better context, such as diffview integration needs to be enabled for "diff head"

Copy link
Member

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. :P

Copy link
Member Author

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

Copy link
Member Author

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 anyway

Copy link
Member

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

return ok and value or false
end,
}),
integrations = {
Copy link
Member Author

@ten3roberts ten3roberts Jul 21, 2023

Choose a reason for hiding this comment

The 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 check_integration function

@ten3roberts ten3roberts requested a review from CKolkey July 21, 2023 22:50
@ten3roberts ten3roberts marked this pull request as ready for review July 22, 2023 16:16
@ten3roberts
Copy link
Member Author

What do you think of this @CKolkey

Copy link
Member

@CKolkey CKolkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change, then good to go :)

end

return true
logger.fmt_info("Found explicit integration '%s' = %s", name, enabled)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to start prefixing these with [LOCATION] to make reading the log easier. So, [CONFIG] in this case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this e09dd40?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bang-on.

@ten3roberts ten3roberts requested a review from CKolkey July 23, 2023 13:46
@ten3roberts ten3roberts merged commit 805a7aa into master Jul 23, 2023
@CKolkey CKolkey deleted the fix-ensure branch July 23, 2023 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants