Skip to content

Commit

Permalink
treewide: use mkWarnings wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Jan 20, 2025
1 parent 2ec6218 commit 60adb6c
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 122 deletions.
10 changes: 6 additions & 4 deletions plugins/by-name/alpha/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ in
lib.mkIf cfg.enable {

# TODO: added 2024-09-20 remove after 24.11
warnings = lib.optionals opt.iconsEnabled.isDefined [
''
warnings = lib.nixvim.mkWarnings "plugins.alpha" {
when = opt.iconsEnabled.isDefined;
message = ''
The option definition `plugins.alpha.iconsEnabled' in ${lib.showFiles opt.iconsEnabled.files} has been deprecated; please remove it.
''
];
'';
};

plugins.web-devicons =
lib.mkIf
(
Expand Down
12 changes: 8 additions & 4 deletions plugins/by-name/clangd-extensions/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings = lib.optionals (!config.plugins.lsp.enable) ''
Nixvim (plugins.clangd-extensions): You have enabled `clangd-extensions` but not the lsp (`plugins.lsp`).
You should set `plugins.lsp.enable = true` to make use of the clangd-extensions' features.
'';
warnings = lib.nixvim.mkWarnings "plugins.clangd-extensions" {
when = !config.plugins.lsp.enable;

message = ''
You have enabled `clangd-extensions` but not the lsp (`plugins.lsp`).
You should set `plugins.lsp.enable = true` to make use of the clangd-extensions' features.
'';
};

plugins.lsp = {
servers.clangd = {
Expand Down
12 changes: 8 additions & 4 deletions plugins/by-name/efmls-configs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ in
extraPlugins = [ cfg.package ];

# TODO: print the location of the offending options
warnings = lib.optional (nixvimPkgs.wrong != [ ]) ''
Nixvim (plugins.efmls-configs): Following tools are not handled by nixvim, please add them to `externallyManagedPackages` to silence this:
${lib.concatMapStringsSep "\n" (tool: " - ${tool}") nixvimPkgs.wrong}
'';
warnings = lib.nixvim.mkWarnings "plugins.efmls-configs" {
when = nixvimPkgs.wrong != [ ];

message = ''
Following tools are not handled by nixvim, please add them to `externallyManagedPackages` to silence this:
${lib.concatMapStringsSep "\n" (tool: " - ${tool}") nixvimPkgs.wrong}
'';
};

plugins.lsp.servers.efm = {
enable = true;
Expand Down
20 changes: 10 additions & 10 deletions plugins/by-name/firenvim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ lib.nixvim.plugins.mkNeovimPlugin {

callSetup = false;
extraConfig = cfg: opts: {
warnings =
lib.optional
(
config.performance.combinePlugins.enable
&& !(lib.elem "firenvim" config.performance.combinePlugins.standalonePlugins)
)
''
Nixvim (plugins.firenvim): Using `performance.combinePlugins` breaks `firenvim`.
Add this plugin to `performance.combinePlugins.standalonePlugins` to prevent any issue.
'';
warnings = lib.nixvim.mkWarnings "plugins.firenvim" {
when =
config.performance.combinePlugins.enable
&& !(lib.elem "firenvim" config.performance.combinePlugins.standalonePlugins);
message = ''
Using `performance.combinePlugins` breaks `firenvim`.
Add this plugin to `performance.combinePlugins.standalonePlugins` to prevent any issue.
'';
};

globals.firenvim_config = lib.modules.mkAliasAndWrapDefsWithPriority lib.id opts.settings;
};
}
22 changes: 11 additions & 11 deletions plugins/by-name/flutter-tools/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ lib.nixvim.plugins.mkNeovimPlugin {
extraConfig = cfg: {
extraPackages = [ cfg.flutterPackage ];

warnings =
lib.optional
(
(cfg.settings ? debugger.enable)
&& (lib.isBool cfg.settings.debugger.enable)
&& cfg.settings.debugger.enable
&& (!config.plugins.dap.enable)
)
''
Nixvim (plugins.flutter-tools): You have enabled the dap integration (`settings.debugger.enable`) but `plugins.dap` is disabled.
'';
warnings = lib.nixvim.mkWarnings "plugins.flutter-tools" {
when =
(cfg.settings ? debugger.enable)
&& (lib.isBool cfg.settings.debugger.enable)
&& cfg.settings.debugger.enable
&& (!config.plugins.dap.enable);

message = ''
You have enabled the dap integration (`settings.debugger.enable`) but `plugins.dap` is disabled.
'';
};
};

settingsOptions = import ./settings-options.nix lib;
Expand Down
16 changes: 9 additions & 7 deletions plugins/by-name/gitsigns/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings =
optional ((isBool cfg.settings.trouble && cfg.settings.trouble) && !config.plugins.trouble.enable)
''
Nixvim (plugins.gitsigns): You have enabled `plugins.gitsigns.settings.trouble` but
`plugins.trouble.enable` is `false`.
You should maybe enable the `trouble` plugin.
'';
warnings = lib.nixvim.mkWarnings "plugins.gitsigns" {
when = (isBool cfg.settings.trouble && cfg.settings.trouble) && !config.plugins.trouble.enable;

message = ''
You have enabled `plugins.gitsigns.settings.trouble` but `plugins.trouble.enable` is `false`.
You should maybe enable the `trouble` plugin.
'';
};

extraPackages = [ cfg.gitPackage ];
};
}
20 changes: 11 additions & 9 deletions plugins/by-name/glance/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings =
lib.optional
(
cfg.settings ? use_trouble_qf
&& builtins.isBool cfg.settings.use_trouble_qf
&& cfg.settings.use_trouble_qf
&& !config.plugins.trouble.enable
)
"Nixvim (plugins.glance): The `trouble` plugin is not enabled, so the `glance` plugin's `use_trouble_qf` setting has no effect.";
warnings = lib.nixvim.mkWarnings "plugins.glance" {
when =
cfg.settings ? use_trouble_qf
&& builtins.isBool cfg.settings.use_trouble_qf
&& cfg.settings.use_trouble_qf
&& !config.plugins.trouble.enable;

message = ''
The `trouble` plugin is not enabled, so the `glance` plugin's `use_trouble_qf` setting has no effect.
'';
};
};
}
10 changes: 7 additions & 3 deletions plugins/by-name/headlines/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = {
warnings = optional (!config.plugins.treesitter.enable) ''
Nixvim (plugins.headlines): headlines requires `plugins.treesitter` to be enabled with the relevant grammars installed.
'';
warnings = lib.nixvim.mkWarnings "plugins.headlines" {
when = !config.plugins.treesitter.enable;

message = ''
headlines requires `plugins.treesitter` to be enabled with the relevant grammars installed.
'';
};
};
}
24 changes: 12 additions & 12 deletions plugins/by-name/lir/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings =
lib.optional
(
(cfg.settings ? devicons.enable)
&& (lib.isBool cfg.settings.devicons.enable)
&& cfg.settings.devicons.enable
&& (!config.plugins.web-devicons.enable)
)
''
Nixvim (plugins.lir): You have enabled `settings.devicons.enable` but `plugins.web-devicons.enable` is `false`.
Consider enabling the plugin for proper devicons support.
'';
warnings = lib.nixvim.mkWarnings "plugins.lir" {
when =
(cfg.settings ? devicons.enable)
&& (lib.isBool cfg.settings.devicons.enable)
&& cfg.settings.devicons.enable
&& (!config.plugins.web-devicons.enable);

message = ''
You have enabled `settings.devicons.enable` but `plugins.web-devicons.enable` is `false`.
Consider enabling the plugin for proper devicons support.
'';
};
};
}
12 changes: 7 additions & 5 deletions plugins/by-name/molten/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,12 @@ mkVimPlugin {
extraConfig = cfg: {
extraPython3Packages = cfg.python3Dependencies;

warnings =
lib.optional (cfg.settings.image_provider == "wezterm" && !config.plugins.wezterm.enable)
''
Nixvim (plugins.molten): The `wezterm` plugin is not enabled, so the `molten` plugin's `image_provider` setting will have no effect.
'';
warnings = lib.nixvim.mkWarnings "plugins.molten" {
when = cfg.settings.image_provider == "wezterm" && !config.plugins.wezterm.enable;

message = ''
The `wezterm` plugin is not enabled, so the `molten` plugin's `image_provider` setting will have no effect.
'';
};
};
}
21 changes: 10 additions & 11 deletions plugins/by-name/neoclip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,16 @@ lib.nixvim.plugins.mkNeovimPlugin {
extraConfig = cfg: {
# TODO: added 2024-09-14 remove after 24.11
plugins.sqlite-lua.enable = mkOverride 1490 true;
warnings =
optional
(
isBool cfg.settings.enable_persistent_history
&& cfg.settings.enable_persistent_history
&& options.plugins.sqlite-lua.enable.highestPrio == 1490
)
''
Nixvim (plugins.neoclip) `sqlite-lua` automatic installation is deprecated.
Please use `plugins.sqlite-lua.enable`.
'';
warnings = lib.nixvim.mkWarnings "plugins.neoclip" {
when =
isBool cfg.settings.enable_persistent_history
&& cfg.settings.enable_persistent_history
&& options.plugins.sqlite-lua.enable.highestPrio == 1490;

message = ''
`sqlite-lua` automatic installation is deprecated. Please use `plugins.sqlite-lua.enable`.
'';
};

assertions = [
{
Expand Down
12 changes: 8 additions & 4 deletions plugins/by-name/neotest/adapters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ let
}
];

warnings = optional (!config.plugins.treesitter.enable) ''
Nixvim (plugins.neotest.adapters.${name}): This adapter requires `treesitter` to be enabled.
You might want to set `plugins.treesitter.enable = true` and ensure that the `${treesitter-parser}` parser is enabled.
'';
warnings = lib.nixvim.mkWarnings "plugins.neotest.adapters.${name}" {
when = !config.plugins.treesitter.enable;

message = ''
This adapter requires `treesitter` to be enabled.
You might want to set `plugins.treesitter.enable = true` and ensure that the `${treesitter-parser}` parser is enabled.
'';
};

plugins.neotest.settings.adapters =
let
Expand Down
35 changes: 20 additions & 15 deletions plugins/by-name/notebook-navigator/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,25 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings =
(lib.optional ((cfg.settings.activate_hydra_keys != null) && (!config.plugins.hydra.enable)) ''
Nixvim (plugins.notebook-navigator): `plugins.notebook-navigator.settings.activate_hydra_keys` has been set to a non-`null`
value but `plugins.hydra.enable` is `false`.
'')
++
(lib.optional ((cfg.settings.repl_provider == "toggleterm") && (!config.plugins.toggleterm.enable)))
''
Nixvim (plugins.notebook-navigator): `plugins.notebook-navigator.settings.repl_provider` has been set to "toggleterm"
but `plugins.hydra.toggleterm.enable` is `false`.
''
++ (lib.optional ((cfg.settings.repl_provider == "molten") && (!config.plugins.molten.enable))) ''
Nixvim (plugins.notebook-navigator): `plugins.notebook-navigator.settings.repl_provider` has been set to "molten"
but `plugins.molten.enable` is `false`.
'';
warnings = lib.nixvim.mkWarnings "plugins.notebook-navigator" [
{
when = (cfg.settings.activate_hydra_keys != null) && (!config.plugins.hydra.enable);
message = ''
`settings.activate_hydra_keys` has been set to a non-`null` value but `plugins.hydra.enable` is `false`.
'';
}
{
when = (cfg.settings.repl_provider == "toggleterm") && (!config.plugins.toggleterm.enable);
message = ''
`settings.repl_provider` has been set to "toggleterm" but `plugins.hydra.toggleterm.enable` is `false`.
'';
}
{
when = (cfg.settings.repl_provider == "molten") && (!config.plugins.molten.enable);
message = ''
`settings.repl_provider` has been set to "molten" but `plugins.molten.enable` is `false`.
'';
}
];
};
}
11 changes: 7 additions & 4 deletions plugins/by-name/rest/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,13 @@ lib.nixvim.plugins.mkNeovimPlugin {
]
];
in
lib.optional (definedOpts != [ ]) ''
Nixvim(plugins.rest): The following v2 settings options are no longer supported in v3:
${lib.concatMapStringsSep "\n" (opt: " - ${lib.showOption (lib.toList opt)}") definedOpts}
'';
lib.nixvim.mkWarnings "plugins.rest" {
when = definedOpts != [ ];
message = ''
The following v2 settings options are no longer supported in v3:
${lib.concatMapStringsSep "\n" (opt: " - ${lib.showOption (lib.toList opt)}") definedOpts}
'';
};

# TODO: There may be some interactions between this & telescope, maybe requiring #2292
plugins.rest.luaConfig.post = lib.mkIf cfg.enableTelescope ''require("telescope").load_extension("rest")'';
Expand Down
13 changes: 8 additions & 5 deletions plugins/by-name/vim-matchup/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ lib.nixvim.plugins.mkVimPlugin {
};

extraConfig = cfg: {
warnings = lib.optional (cfg.treesitter.enable && (!config.plugins.treesitter.enable)) ''
Nixvim (plugins.vim-matchup): `plugins.vim-matchup.treesitter.enable` is `true`, but the
treesitter plugin itself is not.
-> Set `plugins.treesitter.enable` to `true`.
'';
warnings = lib.nixvim.mkWarnings "plugins.vim-matchup" {
when = cfg.treesitter.enable && (!config.plugins.treesitter.enable);

message = ''
`plugins.vim-matchup.treesitter.enable` is `true`, but the treesitter plugin itself is not.
-> Set `plugins.treesitter.enable` to `true`.
'';
};

plugins.treesitter.settings.matchup = cfg.treesitter;
};
Expand Down
16 changes: 9 additions & 7 deletions plugins/by-name/yanky/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,15 @@ lib.nixvim.plugins.mkNeovimPlugin {
extraConfig = cfg: {
# TODO: Added 2024-09-14 remove after 24.11
plugins.sqlite-lua.enable = mkOverride 1490 true;
warnings =
optional
(cfg.settings.ring.storage == "sqlite" && options.plugins.sqlite-lua.enable.highestPrio == 1490)
''
Nixvim (plugins.yanky) `sqlite-lua` automatic installation is deprecated.
Please use `plugins.sqlite-lua.enable`.
'';
warnings = lib.nixvim.mkWarnings "plugins.yanky" {
when =
cfg.settings.ring.storage == "sqlite" && options.plugins.sqlite-lua.enable.highestPrio == 1490;

message = ''
`sqlite-lua` automatic installation is deprecated.
Please use `plugins.sqlite-lua.enable`.
'';
};

assertions = [
{
Expand Down
14 changes: 7 additions & 7 deletions plugins/by-name/zk/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ lib.nixvim.plugins.mkNeovimPlugin {
extraConfig = cfg: {
extraPackages = [ cfg.zkPackage ];

warnings = flatten (
warnings = lib.nixvim.mkWarnings "plugins.zk" (
mapAttrsToList
(
picker: pluginName:
optional ((cfg.settings.picker == picker) && !config.plugins.${pluginName}.enable) ''
Nixvim (plugins.zk): You have set `plugins.zk.settings.picker = "${picker}"` but `plugins.${pluginName}` is not enabled in your config.
''
)
(picker: pluginName: {
when = (cfg.settings.picker == picker) && !config.plugins.${pluginName}.enable;
message = ''
You have set `plugins.zk.settings.picker = "${picker}"` but `plugins.${pluginName}` is not enabled in your config.
'';
})
{
fzf_lua = "fzf-lua";
telescope = "telescope";
Expand Down

0 comments on commit 60adb6c

Please sign in to comment.