From 1748ebaf92098fcc31534317ce93bfa30b6084c4 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Thu, 7 Mar 2024 10:24:34 +0100 Subject: [PATCH] plugins/none-ls: automatic check for tools packages declaration --- plugins/none-ls/servers.nix | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/plugins/none-ls/servers.nix b/plugins/none-ls/servers.nix index 11d6e9c0..2475684d 100644 --- a/plugins/none-ls/servers.nix +++ b/plugins/none-ls/servers.nix @@ -376,6 +376,47 @@ in { enabledSources = builtins.filter (source: source.enable) flattenedSources; in mkIf cfg.enable { + # ASSERTIONS FOR DEVELOPMENT PURPOSES: Any failure should be caught by CI before deployment. + # Ensure that the keys of the manually declared `builtinPackages` match the ones from upstream. + assertions = let + upstreamToolNames = unique ( + flatten + ( + mapAttrsToList + (_: attrNames) + noneLsBuiltins + ) + ); + localToolNames = attrNames builtinPackages; + + undeclaredToolNames = + filter + # Keep tool names which are not declared locally + (toolName: !(elem toolName localToolNames)) + upstreamToolNames; + + uselesslyDeclaredToolNames = + filter + # Keep tool names which are not in upstream + (toolName: !(elem toolName upstreamToolNames)) + localToolNames; + in [ + { + assertion = (length undeclaredToolNames) == 0; + message = '' + Nixvim (plugins.none-ls): Some tools from upstream are not declared locally in `builtinPackages`. + -> [${concatStringsSep ", " undeclaredToolNames}] + ''; + } + { + assertion = (length uselesslyDeclaredToolNames) == 0; + message = '' + Nixvim (plugins.none-ls): Some tools are declared locally but are not in the upstream list of supported plugins. + -> [${concatStringsSep ", " uselesslyDeclaredToolNames}] + ''; + } + ]; + plugins.none-ls.sourcesItems = builtins.map ( source: let