Skip to content

Commit 55bda0c

Browse files
committed
plugins/none-ls/sources: structured "with" settings
Allow supplying strLua or an attrset that will be handled using `toLuaObject`. Included an example and a link to the [upstream documentation]. [upstream documentation]: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md
1 parent ff6ad12 commit 55bda0c

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

plugins/none-ls/_mk-source-plugin.nix

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,26 @@ in
1818
options.plugins.none-ls.sources.${sourceType}.${sourceName} =
1919
{
2020
enable = lib.mkEnableOption "the ${sourceName} ${sourceType} source for none-ls";
21-
withArgs = helpers.mkNullOrOption helpers.nixvimTypes.strLua ''
22-
Raw Lua code passed as an argument to the source's `with` method.
23-
'';
21+
# Support strLua for compatibility with the old withArgs option
22+
settings = helpers.defaultNullOpts.mkStrLuaOr' {
23+
type = with lib.types; attrsOf anything;
24+
description = ''
25+
Options provided to the `require('null-ls').builtins.${sourceType}.${sourceName}.with` function.
26+
27+
See upstream's [`BUILTIN_CONFIG`] documentation.
28+
29+
[`BUILTIN_CONFIG`]: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md
30+
'';
31+
example = {
32+
extra_filetypes = [ "toml" ];
33+
disabled_filetypes = [ "lua" ];
34+
extra_args = [
35+
"-i"
36+
"2"
37+
"-ci"
38+
];
39+
};
40+
};
2441
}
2542
# Only declare a package option if a package is required
2643
// lib.optionalAttrs (packaged ? ${sourceName}) {
@@ -42,11 +59,24 @@ in
4259
);
4360
};
4461

62+
# TODO: Added 2024-07-16; remove after 24.11
63+
imports =
64+
let
65+
basePath = [
66+
"plugins"
67+
"none-ls"
68+
"sources"
69+
sourceType
70+
sourceName
71+
];
72+
in
73+
[ (lib.mkRenamedOptionModule (basePath ++ [ "withArgs" ]) (basePath ++ [ "settings" ])) ];
74+
4575
config = lib.mkIf (cfg.enable && cfg'.enable) {
4676
plugins.none-ls.settings.sources = lib.mkDefault [
4777
(
4878
"require('null-ls').builtins.${sourceType}.${sourceName}"
49-
+ lib.optionalString (cfg'.withArgs != null) ".with(${cfg'.withArgs})"
79+
+ lib.optionalString (cfg'.settings != null) ".with(${helpers.toLuaObject cfg'.settings})"
5080
)
5181
];
5282

0 commit comments

Comments
 (0)