Skip to content

Commit

Permalink
treewide: use mkWarnings where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Jan 29, 2025
1 parent abba4af commit 12e658e
Show file tree
Hide file tree
Showing 34 changed files with 309 additions and 225 deletions.
10 changes: 6 additions & 4 deletions modules/lazyload.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ in
) (builtins.attrNames config.plugins);
count = builtins.length pluginsWithLazyLoad;
in
lib.optionals (count > 0 && !config.plugins.lz-n.enable) [
''
lib.nixvim.mkWarnings "lazy loading" {
when = count > 0 && !config.plugins.lz-n.enable;

message = ''
You have enabled lazy loading support for the following plugins but have not enabled a lazy loading provider.
${lib.concatImapStringsSep "\n" (i: x: "${toString i}. plugins.${x}") pluginsWithLazyLoad}
Currently supported lazy providers:
- lz-n
''
];
'';
};
};
}
13 changes: 8 additions & 5 deletions plugins/by-name/auto-save/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,13 @@ lib.nixvim.plugins.mkNeovimPlugin {
]
];
in
lib.optional (definedOpts != [ ]) ''
Nixvim(plugins.auto-save): The following settings options are no longer supported.
Check the plugin documentation for more details.:
${lib.concatMapStringsSep "\n" (opt: " - ${lib.showOption (lib.toList opt)}") definedOpts}
'';
lib.nixvim.mkWarnings "plugins.auto-save" {
when = definedOpts != [ ];
message = ''
The following settings options are no longer supported.
Check the plugin documentation for more details.:
${lib.concatMapStringsSep "\n" (opt: " - ${lib.showOption (lib.toList opt)}") definedOpts}
'';
};
};
}
27 changes: 16 additions & 11 deletions plugins/by-name/blink-cmp-copilot/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,23 @@ lib.nixvim.plugins.mkNeovimPlugin {
copilot-lua-cfg = config.plugins.copilot-lua.settings;
isEnabled = b: builtins.isBool b && b;
in
lib.optionals (isEnabled copilot-lua-cfg.suggestion.enabled) [
''
It is recommended to disable copilot's `suggestion` module, as it can interfere with
completions properly appearing in blink-cmp-copilot.
''
]
++ lib.optionals (isEnabled copilot-lua-cfg.panel.enabled) [
''
It is recommended to disable copilot's `panel` module, as it can interfere with completions
properly appearing in blink-cmp-copilot.
''
lib.nixvim.mkWarnings "plugins.blink-cmp-copilot" [
{
when = isEnabled copilot-lua-cfg.suggestion.enabled;
message = ''
It is recommended to disable copilot's `suggestion` module, as it can interfere with
completions properly appearing in blink-cmp-copilot.
'';
}
{
when = isEnabled copilot-lua-cfg.panel.enabled;
message = ''
It is recommended to disable copilot's `panel` module, as it can interfere with completions
properly appearing in blink-cmp-copilot.
'';
}
];

plugins.copilot-lua.enable = lib.mkDefault true;
};
}
9 changes: 6 additions & 3 deletions plugins/by-name/blink-cmp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings = lib.optional (cfg.settings ? documentation) ''
Nixvim(plugins.blink): `settings.documentation` does not correspond to a known setting, use `settings.windows.documentation` instead.
'';
warnings = lib.nixvim.mkWarnings "plugins.blink" {
when = cfg.settings ? documentation;
message = ''
`settings.documentation` does not correspond to a known setting, use `settings.windows.documentation` instead.
'';
};
};
}
24 changes: 16 additions & 8 deletions plugins/by-name/copilot-cmp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,22 @@ lib.nixvim.plugins.mkNeovimPlugin {
copilot-lua-cfg = config.plugins.copilot-lua.settings;
isEnabled = b: (lib.isBool b && b);
in
lib.optional (isEnabled copilot-lua-cfg.suggestion.enabled) ''
It is recommended to disable copilot's `suggestion` module, as it can interfere with
completions properly appearing in copilot-cmp.
''
++ lib.optional (isEnabled copilot-lua-cfg.panel.enabled) ''
It is recommended to disable copilot's `panel` module, as it can interfere with completions
properly appearing in copilot-cmp.
'';
lib.nixvim.mkWarnings "plugins.copilot-cmp" [
{
when = isEnabled copilot-lua-cfg.suggestion.enabled;
message = ''
It is recommended to disable copilot's `suggestion` module, as it can interfere with
completions properly appearing in copilot-cmp.
'';
}
{
when = isEnabled copilot-lua-cfg.panel.enabled;
message = ''
It is recommended to disable copilot's `panel` module, as it can interfere with completions
properly appearing in copilot-cmp.
'';
}
];

plugins.copilot-lua.enable = lib.mkDefault true;
};
Expand Down
20 changes: 10 additions & 10 deletions plugins/by-name/fidget/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,16 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings =
lib.optionals
(
(builtins.isBool cfg.settings.integration.nvim-tree.enable)
&& cfg.settings.integration.nvim-tree.enable
&& !config.plugins.nvim-tree.enable
)
[
"Nixvim(plugins.fidget): You have set `plugins.fidget.settings.integrations.nvim-tree.enable` to true but have not enabled `plugins.nvim-tree`."
];
warnings = lib.nixvim.mkWarnings "plugins.fidget" {
when =
(builtins.isBool cfg.settings.integration.nvim-tree.enable)
&& cfg.settings.integration.nvim-tree.enable
&& !config.plugins.nvim-tree.enable;

message = ''
You have set `plugins.fidget.settings.integrations.nvim-tree.enable` to true but have not enabled `plugins.nvim-tree`.
'';
};
};

inherit (import ./deprecations.nix { inherit lib; }) imports optionsRenamedToSettings;
Expand Down
11 changes: 7 additions & 4 deletions plugins/by-name/fzf-lua/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,14 @@ lib.nixvim.plugins.mkNeovimPlugin {

extraConfig = cfg: opts: {
# TODO: deprecated 2024-08-29 remove after 24.11
warnings = lib.optionals opts.iconsEnabled.isDefined [
''
warnings = lib.nixvim.mkWarnings "plugins.fzf-lua" {
when = opts.iconsEnabled.isDefined;

message = ''
The option definition `plugins.fzf-lua.iconsEnabled' in ${lib.showFiles opts.iconsEnabled.files} has been deprecated; please remove it.
''
];
'';
};

# TODO: added 2024-09-20 remove after 24.11
plugins.web-devicons =
lib.mkIf
Expand Down
7 changes: 4 additions & 3 deletions plugins/by-name/hmts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ lib.nixvim.plugins.mkNeovimPlugin {
hasSettings = false;
hasLuaConfig = false;
extraConfig = {
warnings = lib.optional (
!config.plugins.treesitter.enable
) "Nixvim: hmts needs treesitter to function as intended";
warnings = lib.nixvim.mkWarnings "plugins.hmts" {
when = !config.plugins.treesitter.enable;
message = "hmts needs treesitter to function as intended";
};
};
}
47 changes: 21 additions & 26 deletions plugins/by-name/lazydev/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,33 +135,28 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings =
lib.optionals
(
warnings = lib.nixvim.mkWarnings "plugins.lazydev" [
{
when =
builtins.isBool cfg.settings.integrations.cmp
&& !config.plugins.cmp.enable
&& cfg.settings.integrations.cmp
)
[ "Nixvim(plugins.lazydev): you have enabled nvim-cmp integration but plugins.cmp is not enabled." ]
++
lib.optionals
(
builtins.isBool cfg.settings.integrations.lspconfig
&& !config.plugins.lsp.enable
&& cfg.settings.integrations.lspconfig
)
[
"Nixvim(plugins.lazydev): you have enabled lspconfig integration but plugins.lsp is not enabled."
]
++
lib.optionals
(
builtins.isBool cfg.settings.integrations.coq
&& !config.plugins.coq-nvim.enable
&& cfg.settings.integrations.coq
)
[
"Nixvim(plugins.lazydev): you have enabled coq integration but plugins.coq-nvim is not enabled."
];
&& cfg.settings.integrations.cmp;
message = "You have enabled nvim-cmp integration but plugins.cmp is not enabled.";
}
{
when =
builtins.isBool cfg.settings.integrations.lspconfig
&& !config.plugins.lsp.enable
&& cfg.settings.integrations.lspconfig;
message = "You have enabled lspconfig integration but plugins.lsp is not enabled.";
}
{
when =
builtins.isBool cfg.settings.integrations.coq
&& !config.plugins.coq-nvim.enable
&& cfg.settings.integrations.coq;
message = "You have enabled coq integration but plugins.coq-nvim is not enabled.";
}
];
};
}
9 changes: 6 additions & 3 deletions plugins/by-name/lsp-format/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings = lib.mkIf (!config.plugins.lsp.enable) [
"You have enabled `plugins.lsp-format` but have `plugins.lsp` disabled."
];
warnings = lib.nixvim.mkWarnings "plugins.lsp-format" {
when = !config.plugins.lsp.enable;
message = ''
This plugin requires `plugins.lsp` to be enabled.
'';
};

plugins.lsp = {
onAttach =
Expand Down
13 changes: 9 additions & 4 deletions plugins/by-name/lspsaga/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,16 @@ in
{
enable = mkOverride 1490 true;
};
warnings = lib.optional (
warnings = lib.nixvim.mkWarnings "plugins.ltex-extra" {
# https://nvimdev.github.io/lspsaga/implement/#default-options
(isBool cfg.implement.enable && cfg.implement.enable)
&& (isBool cfg.symbolInWinbar.enable && !cfg.symbolInWinbar.enable)
) "You have enabled the `implement` module but it requires `symbolInWinbar` to be enabled.";
when =
(isBool cfg.implement.enable && cfg.implement.enable)
&& (isBool cfg.symbolInWinbar.enable && !cfg.symbolInWinbar.enable);

message = ''
You have enabled the `implement` module but it requires `symbolInWinbar` to be enabled.
'';
};

extraPlugins = [ cfg.package ];
extraConfigLua =
Expand Down
11 changes: 7 additions & 4 deletions plugins/by-name/ltex-extra/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings = optional (!config.plugins.lsp.enable) ''
You have enabled `ltex-extra` but not the lsp (`plugins.lsp`).
You should set `plugins.lsp.enable = true` to make use of the LTeX_extra plugin's features.
'';
warnings = lib.nixvim.mkWarnings "plugins.ltex-extra" {
when = !config.plugins.lsp.enable;
message = ''
You have enabled `ltex-extra` but not the lsp (`plugins.lsp`).
You should set `plugins.lsp.enable = true` to make use of the LTeX_extra plugin's features.
'';
};

plugins.lsp = {
servers.ltex = {
Expand Down
33 changes: 22 additions & 11 deletions plugins/by-name/neorg/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,27 @@ lib.nixvim.plugins.mkNeovimPlugin {
modules = cfg.settings.load or { };
telescopeModuleEnabled = (modules."core.integrations.telescope" or null) != null;
in
(lib.optional (telescopeModuleEnabled && (!cfg.telescopeIntegration.enable)) ''
You have enabled the telescope neorg module (`core.integrations.telescope`) but have not enabled `plugins.neorg.telescopeIntegration.enable`.
The latter will install the `neorg-telescope` plugin necessary for this integration to work.
'')
++ (lib.optional (cfg.telescopeIntegration.enable && (!config.plugins.telescope.enable)) ''
Telescope support for neorg is enabled but the telescope plugin is not.
'')
++ (lib.optional ((modules ? "core.defaults") && (!config.plugins.treesitter.enable)) ''
Neorg's `core.defaults` module is enabled but `plugins.treesitter` is not.
Treesitter is required when using the `core.defaults`.
'');
lib.nixvim.mkWarnings "plugins.neorg" [
{
when = telescopeModuleEnabled && (!cfg.telescopeIntegration.enable);
message = ''
You have enabled the telescope neorg module (`core.integrations.telescope`) but have not enabled `plugins.neorg.telescopeIntegration.enable`.
The latter will install the `neorg-telescope` plugin necessary for this integration to work.
'';
}
{
when = cfg.telescopeIntegration.enable && (!config.plugins.telescope.enable);
message = ''
Telescope support for neorg is enabled but the telescope plugin is not.
'';
}
{
when = (modules ? "core.defaults") && (!config.plugins.treesitter.enable);
message = ''
Neorg's `core.defaults` module is enabled but `plugins.treesitter` is not.
Treesitter is required when using the `core.defaults`.
'';
}
];
};
}
17 changes: 10 additions & 7 deletions plugins/by-name/none-ls/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,16 @@ lib.nixvim.plugins.mkNeovimPlugin {
};
in
{
warnings = lib.optional (cfg.enableLspFormat && cfg.settings.on_attach != null) ''
You have enabled the lsp-format integration with none-ls.
However, you have provided a custom value to `plugins.none-ls.settings.on_attach`.
This means the `enableLspFormat` option will have no effect.
Final value is:
${lib.generators.toPretty { } cfg.settings.on_attach}
'';
warnings = lib.nixvim.mkWarnings "plugins.none-ls" {
when = cfg.enableLspFormat && cfg.settings.on_attach != null;
message = ''
You have enabled the lsp-format integration with none-ls.
However, you have provided a custom value to `plugins.none-ls.settings.on_attach`.
This means the `enableLspFormat` option will have no effect.
Final value is:
${lib.generators.toPretty { } cfg.settings.on_attach}
'';
};

assertions = [
{
Expand Down
20 changes: 11 additions & 9 deletions plugins/by-name/none-ls/prettier.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ in
};

config = lib.mkIf cfg.enable {
warnings =
lib.optional (opt.disableTsServerFormatter.highestPrio == defaultPrio && ts-ls-cfg.enable)
''
You have enabled the `prettier` formatter in none-ls.
You have also enabled the `ts_ls` language server which also brings a formatting feature.
warnings = lib.nixvim.mkWarnings "plugins.none-ls.sources.formatting.prettier" {
when = opt.disableTsServerFormatter.highestPrio == defaultPrio && ts-ls-cfg.enable;

- To disable the formatter built-in the `ts_ls` language server, set
`plugins.none-ls.sources.formatting.prettier.disableTsServerFormatter` to `true`.
- Else, to silence this warning, explicitly set the option to `false`.
'';
message = ''
You have enabled the `prettier` formatter in none-ls.
You have also enabled the `ts_ls` language server which also brings a formatting feature.
- To disable the formatter built-in the `ts_ls` language server, set
`plugins.none-ls.sources.formatting.prettier.disableTsServerFormatter` to `true`.
- Else, to silence this warning, explicitly set the option to `false`.
'';
};

plugins.lsp.servers.ts_ls =
lib.mkIf (cfg.enable && ts-ls-cfg.enable && cfg.disableTsServerFormatter)
Expand Down
Loading

0 comments on commit 12e658e

Please sign in to comment.