Skip to content
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

feat: add ignore_methods to ignore setup of null-ls source method types #93

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ local DEFAULT_SETTINGS = {
-- A list of sources to install if they're not already installed.
-- This setting has no relation with the `automatic_installation` setting.
ensure_installed = {},
-- A list of null-ls methods to ignore when calling handlers.
-- This setting is useful if some functionality is handled by other plugins such as `conform` and `nvim-lint`
ignore_methods = {},
-- Run `require("null-ls").setup`.
-- Will automatically install masons tools based on selected sources in `null-ls`.
-- Can also be an exclusion list.
Expand Down
4 changes: 4 additions & 0 deletions lua/mason-null-ls/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ local function setup_handlers(handlers)
Optional.of_nilable(handlers[source_name]):or_(_.always(default_handler)):if_present(function(handler)
log.fmt_trace('Calling handler for %s', source_name)

local ignored_methods = require('mason-null-ls.settings').current.ignore_methods
local types = _.filter_map(function(method)
if vim.tbl_contains(ignored_methods, method) then
Copy link
Owner

@jay-babu jay-babu Feb 8, 2024

Choose a reason for hiding this comment

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

I was thinking why not just allow line 54 to be overridden with allowed_methods. Also that's interesting, people can't just replace null-ls completely. You need it somewhat still

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think it just becomes more verbose to list off allowed methods. It's more typical you just want to ignore them. I'm good either way !

Definitely when building extra lazy specs such as in LazyVim extras and AstroCommunity it makes it easier to be additive when it's ignore because you can add those in rather than hope that the opts currently have the full allowed_methods populated and then to remove a method. If that makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is an example of it making sense for it to be ignore_methods if you are interested: https://github.com/AstroNvim/astrocommunity/pull/756/files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened another PR as a different approach/option for tackling this type of thing. Let me know what you think!

return Optional.empty()
end
local ok, _ = pcall(require, string.format('null-ls.builtins.%s.%s', method, source_name))
if ok then
return Optional.of(method)
Expand Down
5 changes: 5 additions & 0 deletions lua/mason-null-ls/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ local M = {}

---@class MasonNullLsSettings
---@field handlers table | nil
---@field ignore_methods table
---@field ensure_installed table
---@field automatic_installation boolean | table
local DEFAULT_SETTINGS = {
-- A list of sources to automatically install if they're not already installed. Example: { "stylua" }
-- This setting has no relation with the `automatic_installation` setting.
ensure_installed = {},
-- A list of null-ls methods to ignore when calling handlers.
-- This setting is useful if some functionality is handled by other plugins such as `conform` and `nvim-lint`
ignore_methods = {},
-- NOTE: this is left here for future porting in case needed
-- Whether sources that are set up (via null-ls) should be automatically installed if they're not already installed.
-- This setting has no relation with the `ensure_installed` setting.
Expand All @@ -28,6 +32,7 @@ function M.set(opts)
M.current = vim.tbl_deep_extend('force', M.current, opts)
vim.validate({
ensure_installed = { M.current.ensure_installed, 'table', true },
ignore_methods = { M.current.ignore_methods, 'table', true },
automatic_installation = { M.current.automatic_installation, { 'boolean', 'table' }, true },
handlers = { M.current.handlers, { 'table' }, true },
})
Expand Down
Loading