From 17e13d478de2c088476058a8272b8b6f3e24ddfe Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Thu, 8 May 2025 23:53:22 +0100 Subject: [PATCH] plugins/oil-git-status: improve `signcolumn` warning The warning should trigger when a valid value is configured that restricts the sign column to less than 2 columns. --- plugins/by-name/oil-git-status/default.nix | 61 ++++++++++++------- .../by-name/oil-git-status/default.nix | 15 +++++ 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/plugins/by-name/oil-git-status/default.nix b/plugins/by-name/oil-git-status/default.nix index 4d34fc4a..3c16f84e 100644 --- a/plugins/by-name/oil-git-status/default.nix +++ b/plugins/by-name/oil-git-status/default.nix @@ -58,29 +58,46 @@ lib.nixvim.plugins.mkNeovimPlugin { ${options.plugins.oil.enable} = true; ''; } - { - when = - let - value = config.plugins.oil.settings.win_options.signcolumn or null; - isKnownBadStr = lib.lists.elem value [ - "yes" - "yes:" - "yes:0" - "yes:1" - ]; - hasYes = lib.strings.hasInfix "yes" value; - in - !(lib.strings.isString value && hasYes && !isKnownBadStr); + ( + # The plugin requires the oil configuration allow at least 2 sign columns. + # They suggest `win_options.signcolumn = "yes:2"`, but valid options include + # any "yes" or "auto" with a max > 1: E.g. "auto:2", "auto:1-2", "yes:3", … + # See also `:h 'signcolumn'` + let + # Get `signcolumn` setting value + value = config.plugins.oil.settings.win_options.signcolumn or null; - message = '' - This plugin requires the following `plugins.oil` setting: - ${options.plugins.oil.settings} = { - win_options = { - signcolumn = "yes:2"; - }; - };` - ''; - } + # These valid values do not allow the sign column to use more than one column, + # So they are incompatible with oil-git-status. + badValue = builtins.elem value [ + "no" + "number" + "auto" + "auto:1" + "yes" + "yes:1" + ]; + + currentValueNote = + lib.optionalString (value != null) + "\n`${options.plugins.oil.settings}.win_options.signcolumn` is currently set to ${ + lib.generators.toPretty { } value + }."; + in + { + when = builtins.isString value -> badValue; + message = '' + This plugin requires `plugins.oil` is configured to allow at least 2 sign columns.${currentValueNote} + E.g: + ${options.plugins.oil.settings} = { + win_options = { + signcolumn = "yes:2"; + }; + };` + See :h 'signcolumn' for more options + ''; + } + ) ]; }; diff --git a/tests/test-sources/plugins/by-name/oil-git-status/default.nix b/tests/test-sources/plugins/by-name/oil-git-status/default.nix index 91581cd3..7415e5ed 100644 --- a/tests/test-sources/plugins/by-name/oil-git-status/default.nix +++ b/tests/test-sources/plugins/by-name/oil-git-status/default.nix @@ -31,4 +31,19 @@ plugins.oil-git-status.enable = true; }; + bad-signcolumn_yes = { + test.buildNixvim = false; + test.warnings = expect: [ + (expect "count" 1) + (expect "any" "Nixvim (plugins.oil-git-status): This plugin requires `plugins.oil` is configured to allow at least 2 sign columns.") + (expect "any" "`plugins.oil.settings.win_options.signcolumn` is currently set to \"yes\".") + ]; + + plugins.oil = { + enable = true; + # Should trigger the warning + settings.win_options.signcolumn = "yes"; + }; + plugins.oil-git-status.enable = true; + }; }