nvimtools / none-ls.nvim

null-ls.nvim reloaded / Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua.
The Unlicense
2.39k stars 69 forks source link

Include some formatter default `[runtime_]condition`s #152

Closed barrett-ruth closed 2 months ago

barrett-ruth commented 2 months ago

Issues

Feature description

Some formatters (i.e. cbfmt):

Currently, cbfmt will attach to every markdown/org buffer. In this case I believe it makes sense to conditionally attach if .cbfmt.toml for example, exists.

However, I understand that [runtime_]condition have overhead- even though it'll just be checking for a single file.

That or, I can just write a PR to BUILTINS.md including the condition function beneath cbfmt. That may be the simpler solution.

Help

Yes

Implementation help

No response

mochaaP commented 2 months ago

I believe it should be possible to do this with the condition key:

null_ls.builtins.formatting.cbfmt.with({
        -- cbfmt requires a config file
        condition = function(utils)
            return utils.root_has_file(".cbfmt.toml")
        end,
})

Maybe I should add it to cbfmt's docs.

barrett-ruth commented 2 months ago

Yes, my question was about where that should be the default - included in the generator

mochaaP commented 2 months ago

This should work - please test it. :)

barrett-ruth commented 2 months ago

Brilliant works perfectly @mochaaP thanks for catching treefmt or whatever the other one as well. Feel free to merge and close