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 authored and nix-infra-bot committed Jan 20, 2025
1 parent 02e16b2 commit 2ec6218
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 59 deletions.
13 changes: 7 additions & 6 deletions plugins/by-name/haskell-scope-highlighting/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
lib,
helpers,
config,
...
}:
with lib;
lib.nixvim.plugins.mkVimPlugin {
name = "haskell-scope-highlighting";
packPathName = "haskell-scope-highlighting.nvim";
Expand All @@ -13,9 +11,12 @@ lib.nixvim.plugins.mkVimPlugin {
maintainers = [ lib.maintainers.GaetanLepage ];

extraConfig = {
warnings = optional (!config.plugins.treesitter.enable) ''
Nixvim (plugins.haskell-scope-highlighting): haskell-scope-highlighting needs treesitter to function as intended.
Please, enable it by setting `plugins.treesitter.enable` to `true`.
'';
warnings = lib.nixvim.mkWarnings "plugins.haskell-scope-highlighting" {
when = !config.plugins.treesitter.enable;
message = ''
haskell-scope-highlighting needs treesitter to function as intended.
Please, enable it by setting `plugins.treesitter.enable` to `true`.
'';
};
};
}
14 changes: 7 additions & 7 deletions plugins/by-name/nvim-autopairs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings =
optional
((isBool cfg.settings.check_ts) && cfg.settings.check_ts && !config.plugins.treesitter.enable)
''
Nixvim (plugins.nvim-autopairs): You have set `settings.check_ts` to `true` but have not enabled the treesitter plugin.
We suggest you to set `plugins.treesitter.enable` to `true`.
'';
warnings = lib.nixvim.mkWarnings "plugins.nvim-autopairs" {
when = (isBool cfg.settings.check_ts) && cfg.settings.check_ts && !config.plugins.treesitter.enable;
message = ''
You have set `settings.check_ts` to `true` but have not enabled the treesitter plugin.
We suggest you to set `plugins.treesitter.enable` to `true`.
'';
};
};
}
15 changes: 9 additions & 6 deletions plugins/by-name/obsidian/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,16 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings =
let
nvimCmpEnabled = isBool cfg.settings.completion.nvim_cmp && cfg.settings.completion.nvim_cmp;
in
optional (nvimCmpEnabled && !config.plugins.cmp.enable) ''
Nixvim (plugins.obsidian): You have enabled `completion.nvim_cmp` but `plugins.cmp.enable` is `false`.
warnings = lib.nixvim.mkWarnings "plugins.obsidian" {
when =
let
nvimCmpEnabled = isBool cfg.settings.completion.nvim_cmp && cfg.settings.completion.nvim_cmp;
in
nvimCmpEnabled && (!config.plugins.cmp.enable);
message = ''
You have enabled `completion.nvim_cmp` but `plugins.cmp.enable` is `false`.
You should probably enable `nvim-cmp`.
'';
};
};
}
24 changes: 12 additions & 12 deletions plugins/by-name/rustaceanvim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ lib.nixvim.plugins.mkNeovimPlugin {
];

# TODO: remove after 24.11
warnings =
optional
(hasAttrByPath [
"settings"
"server"
"settings"
] cfg)
''
The `plugins.rustaceanvim.settings.server.settings' option has been renamed to `plugins.rustaceanvim.settings.server.default_settings'.
warnings = lib.nixvim.mkWarnings "plugins.rustaceanvim" {
when = hasAttrByPath [
"settings"
"server"
"settings"
] cfg;
message = ''
The `settings.server.settings' option has been renamed to `settings.server.default_settings'.
Note that if you supplied an attrset and not a function you need to set this attr set in:
`plugins.rustaceanvim.settings.server.default_settings.rust-analyzer'.
'';
Note that if you supplied an attrset and not a function you need to set this attr set in:
`settings.server.default_settings.rust-analyzer'.
'';
};
}
# If nvim-lspconfig is enabled:
(mkIf config.plugins.lsp.enable {
Expand Down
13 changes: 7 additions & 6 deletions plugins/by-name/twilight/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
warnings =
optional
((isBool cfg.settings.treesitter) && cfg.settings.treesitter && (!config.plugins.treesitter.enable))
''
Nixvim (plugins.twilight): You have set `plugins.twilight.treesitter` to `true` but `plugins.treesitter.enable` is false.
'';
warnings = lib.nixvim.mkWarnings "plugins.twilight" {
when =
(isBool cfg.settings.treesitter) && cfg.settings.treesitter && (!config.plugins.treesitter.enable);
message = ''
You have set `plugins.twilight.treesitter` to `true` but `plugins.treesitter.enable` is false.
'';
};
};
}
33 changes: 20 additions & 13 deletions plugins/cmp/auto-enable.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,29 @@ in
config = lib.mkIf (cfg.enable && cfg.autoEnableSources) (
lib.mkMerge [
{
warnings =
warnings = lib.nixvim.mkWarnings "plugins.cmp" [
# TODO: expand this warning to ft & cmd sources lists and `showDefs` the offending definitions
lib.optional (lib.types.isRawType cfg.settings.sources) ''
Nixvim (plugins.cmp): You have enabled `autoEnableSources` that tells Nixvim to automatically
enable the source plugins with respect to the list of sources provided in `settings.sources`.
However, the latter is proveded as a raw lua string which is not parseable by Nixvim.
{
when = lib.types.isRawType cfg.settings.sources;
message = ''
You have enabled `autoEnableSources` that tells Nixvim to automatically
enable the source plugins with respect to the list of sources provided in `settings.sources`.
However, the latter is proveded as a raw lua string which is not parseable by Nixvim.
If you want to keep using raw lua for defining your sources:
- Ensure you enable the relevant plugins manually in your configuration;
- Dismiss this warning by explicitly setting `autoEnableSources` to `false`;
''
If you want to keep using raw lua for defining your sources:
- Ensure you enable the relevant plugins manually in your configuration;
- Dismiss this warning by explicitly setting `autoEnableSources` to `false`;
'';
}
# TODO: Added 2024-09-22; remove after 24.11
++ lib.optional (lib.elem "otter" enabledSources) ''
Nixvim (plugins.cmp): "otter" is listed in `settings.sources`, however it is no longer a cmp source.
Instead, you should enable `plugins.otter` and use the "cmp-nvim-lsp" completion source.
'';
{
when = lib.elem "otter" enabledSources;
message = ''
"otter" is listed in `settings.sources`, however it is no longer a cmp source.
Instead, you should enable `plugins.otter` and use the "cmp-nvim-lsp" completion source.
'';
}
];

# If the user has enabled the `foo` and `bar` sources, then `plugins` will look like:
# {
Expand Down
19 changes: 10 additions & 9 deletions plugins/colorschemes/monokai-pro.nix
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,15 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

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

0 comments on commit 2ec6218

Please sign in to comment.