From c5bc3109e677c00b5b39a246cbf846069d2d6c89 Mon Sep 17 00:00:00 2001 From: bandithedoge Date: Sun, 5 May 2024 16:19:54 +0200 Subject: [PATCH] format repo with alejandra --- flake.nix | 112 ++++++++--------- tests.nix | 357 +++++++++++++++++++++++++++--------------------------- 2 files changed, 239 insertions(+), 230 deletions(-) diff --git a/flake.nix b/flake.nix index b6a145c..f43c8fa 100644 --- a/flake.nix +++ b/flake.nix @@ -16,62 +16,66 @@ flake = false; }; }; - outputs = - { self - , nixpkgs - , flake-utils - , norg - , norg-meta - , neorg - , neorg-telescope - , ... - }: { - overlays.default = final: prev: - let inherit (final.lib) attrValues elem filter filterAttrs isDerivation; in - { - vimPlugins = prev.vimPlugins.extend (f: p: { - nvim-treesitter = - let - norgGrammars = { - tree-sitter-norg = norg.defaultPackage.${final.system}; - tree-sitter-norg-meta = norg-meta.defaultPackage.${final.system}; - }; - builtGrammars = (filterAttrs (_: isDerivation) p.nvim-treesitter.builtGrammars) // norgGrammars; - allGrammars = attrValues builtGrammars; - withPlugins = grammarFn: - p.nvim-treesitter.withPlugins (_: - let plugins = (grammarFn builtGrammars); in - plugins ++ (filter (p: !(elem p plugins)) (attrValues norgGrammars)) - ); - withAllGrammars = withPlugins (_: allGrammars); - in - p.nvim-treesitter.overrideAttrs (a: - { - passthru = { - inherit builtGrammars allGrammars withPlugins withAllGrammars; - }; - }); - neorg = final.vimUtils.buildVimPlugin { - pname = "neorg"; - version = neorg.rev; - src = neorg; - dependencies = [ f.plenary-nvim (f.nvim-treesitter.withPlugins (_: [ ])) ]; + outputs = { + self, + nixpkgs, + flake-utils, + norg, + norg-meta, + neorg, + neorg-telescope, + ... + }: + { + overlays.default = final: prev: let + inherit (final.lib) attrValues elem filter filterAttrs isDerivation; + in { + vimPlugins = prev.vimPlugins.extend (f: p: { + nvim-treesitter = let + norgGrammars = { + tree-sitter-norg = norg.defaultPackage.${final.system}; + tree-sitter-norg-meta = norg-meta.defaultPackage.${final.system}; }; - neorg-telescope = final.vimUtils.buildVimPlugin { - pname = "neorg-telescope"; - version = neorg-telescope.rev; - src = neorg-telescope; - dependencies = [ f.telescope-nvim f.neorg ]; - }; - }); - }; + builtGrammars = (filterAttrs (_: isDerivation) p.nvim-treesitter.builtGrammars) // norgGrammars; + allGrammars = attrValues builtGrammars; + withPlugins = grammarFn: + p.nvim-treesitter.withPlugins ( + _: let + plugins = grammarFn builtGrammars; + in + plugins ++ (filter (p: !(elem p plugins)) (attrValues norgGrammars)) + ); + withAllGrammars = withPlugins (_: allGrammars); + in + p.nvim-treesitter.overrideAttrs (a: { + passthru = { + inherit builtGrammars allGrammars withPlugins withAllGrammars; + }; + }); + neorg = final.vimUtils.buildVimPlugin { + pname = "neorg"; + version = neorg.rev; + src = neorg; + dependencies = [f.plenary-nvim (f.nvim-treesitter.withPlugins (_: []))]; + }; + neorg-telescope = final.vimUtils.buildVimPlugin { + pname = "neorg-telescope"; + version = neorg-telescope.rev; + src = neorg-telescope; + dependencies = [f.telescope-nvim f.neorg]; + }; + }); + }; # https://github.com/NixOS/nix/issues/5532 overlay = nixpkgs.lib.warn "`neorg-overlay.overlay` is deprecated; use `neorg-overlay.overlays.default` instead" self.overlays.default; - } // (flake-utils.lib.eachDefaultSystem (system: { - checks = import ./tests.nix - (import nixpkgs { - inherit system; - overlays = [ self.overlays.default ]; - }); + } + // (flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [self.overlays.default]; + }; + in { + checks = import ./tests.nix pkgs; + formatter = pkgs.alejandra; })); } diff --git a/tests.nix b/tests.nix index fb3cda6..7052f2b 100644 --- a/tests.nix +++ b/tests.nix @@ -1,61 +1,68 @@ -pkgs: -let +pkgs: let inherit (pkgs.lib) concatStringsSep imap listToAttrs; - makeTest = { name, plugins, expectedPluginFiles, expectedParsers }: - let - config = - let base = (pkgs.neovimUtils.makeNeovimConfig { inherit plugins; }); - in base // { - wrapRc = false; - wrapperArgs = base.wrapperArgs ++ [ + makeTest = { + name, + plugins, + expectedPluginFiles, + expectedParsers, + }: let + config = let + base = pkgs.neovimUtils.makeNeovimConfig {inherit plugins;}; + in + base + // { + wrapRc = false; + wrapperArgs = + base.wrapperArgs + ++ [ "--add-flags" "'-u' '${ - pkgs.writeText "init.lua" '' - function test() - local success = true + pkgs.writeText "init.lua" '' + function test() + local success = true - require("nvim-treesitter.configs").setup({}) - local parsers = require("nvim-treesitter.parsers") - for _, p in ipairs({${ - concatStringsSep "," (map (p: ''"${p}"'') expectedParsers) - }}) do - if not parsers.has_parser(p) then - print("${name}: missing parser: " .. p) - success = false - end + require("nvim-treesitter.configs").setup({}) + local parsers = require("nvim-treesitter.parsers") + for _, p in ipairs({${ + concatStringsSep "," (map (p: ''"${p}"'') expectedParsers) + }}) do + if not parsers.has_parser(p) then + print("${name}: missing parser: " .. p) + success = false end + end - function has_script(scripts, script) - local filtered = vim.tbl_filter( - function(s) - return string.find(s, script, 1, true) - end, scripts - ) - return #filtered > 0 - end - local scripts = vim.split( - vim.api.nvim_exec("scriptnames", true), "\n", {trimempty = true} + function has_script(scripts, script) + local filtered = vim.tbl_filter( + function(s) + return string.find(s, script, 1, true) + end, scripts ) - for _, s in ipairs({${ - concatStringsSep "," (map (p: ''"${p}"'') expectedPluginFiles) - }}) do - if not has_script(scripts, s) then - print("${name}: missing plugin script:", s) - success = false - end + return #filtered > 0 + end + local scripts = vim.split( + vim.api.nvim_exec("scriptnames", true), "\n", {trimempty = true} + ) + for _, s in ipairs({${ + concatStringsSep "," (map (p: ''"${p}"'') expectedPluginFiles) + }}) do + if not has_script(scripts, s) then + print("${name}: missing plugin script:", s) + success = false end - - print("${name}-result:", success) end - vim.cmd("autocmd BufEnter * lua test()") - '' - }'" + print("${name}-result:", success) + end + + vim.cmd("autocmd BufEnter * lua test()") + '' + }'" ]; - }; - nvim = pkgs.wrapNeovimUnstable pkgs.neovim-unwrapped config; - in - pkgs.runCommand name { } '' + }; + nvim = pkgs.wrapNeovimUnstable pkgs.neovim-unwrapped config; + in + pkgs.runCommand name {} '' tmp=$(mktemp -d) cleanup() { if [[ -d $tmp ]]; then @@ -69,133 +76,131 @@ let touch $out [[ "$(tail -n 1 <<<"$output")" == "${name}-result: true" ]] ''; - tests = - let - pluginMarkers = { - neorg = "ftdetect/norg.vim"; - plenary = "plugin/plenary.vim"; - nvim-treesitter = "plugin/nvim-treesitter.lua"; - telescope = "plugin/telescope.lua"; - }; - in - [ - { - # 1. Just neorg — should automatically pull in plugin and parser dependencies - plugins = with pkgs.vimPlugins; [ neorg ]; - expectedPluginFiles = with pluginMarkers; [ neorg plenary nvim-treesitter ]; - expectedParsers = [ - "norg" - "norg_meta" - ]; - } - # 2. Additional parser — should add to our parsers. - { - plugins = with pkgs.vimPlugins; [ - neorg - (nvim-treesitter.withPlugins (p: [ p.tree-sitter-bash ])) - ]; - expectedPluginFiles = with pluginMarkers; [ neorg plenary nvim-treesitter ]; - expectedParsers = [ "bash" "norg" "norg_meta" ]; - } - # 3. Requesting just norg parser — should add norg_meta parser. - { - plugins = with pkgs.vimPlugins; [ - neorg - (nvim-treesitter.withPlugins (p: [ p.tree-sitter-norg ])) - ]; - expectedPluginFiles = with pluginMarkers; [ neorg plenary nvim-treesitter ]; - expectedParsers = [ "norg" "norg_meta" ]; - } - # 4. Requesting norg and norg-meta parsers — shouldn't lead to duplicates (which - # would fail the derivation of the parser dir) - { - plugins = with pkgs.vimPlugins; [ - neorg - (nvim-treesitter.withPlugins - (p: [ p.tree-sitter-norg p.tree-sitter-norg-meta ])) - ]; - expectedPluginFiles = with pluginMarkers; [ neorg plenary nvim-treesitter ]; - expectedParsers = [ "norg" "norg_meta" ]; - } - # 5. Requesting norg and unrelated parser — should add norg-meta. - { - plugins = with pkgs.vimPlugins; [ - neorg - (nvim-treesitter.withPlugins (p: [ p.tree-sitter-bash p.tree-sitter-norg ])) - ]; - expectedPluginFiles = with pluginMarkers; [ neorg plenary nvim-treesitter ]; - expectedParsers = [ "norg" "norg_meta" "bash" ]; - } - # 6. withAllGrammars — should include our parsers… - { - plugins = with pkgs.vimPlugins; [ neorg nvim-treesitter.withAllGrammars ]; - expectedPluginFiles = with pluginMarkers; [ neorg plenary nvim-treesitter ]; - expectedParsers = [ - "norg" - "norg_meta" - # exemplary for "all": - "bash" - "perl" - ]; - } - # 7. …using allGrammars — as in 6. - { - plugins = with pkgs.vimPlugins; [ - neorg - (nvim-treesitter.withPlugins (_: nvim-treesitter.allGrammars)) - ]; - expectedPluginFiles = with pluginMarkers; [ neorg plenary nvim-treesitter ]; - expectedParsers = [ - "norg" - "norg_meta" - # exemplary for "all": - "bash" - "perl" - ]; - } - # 8. Requesting just neorg-telescope — should pull in all required vim plugins and - # our parsers… - { - plugins = with pkgs.vimPlugins; [ neorg-telescope ]; - expectedPluginFiles = with pluginMarkers; [ - telescope - neorg - plenary - nvim-treesitter - ]; - expectedParsers = [ "norg" "norg_meta" ]; - } - # 9. …with explicit neorg request — as in 8. … - { - plugins = with pkgs.vimPlugins; [ neorg neorg-telescope ]; - expectedPluginFiles = with pluginMarkers; [ - telescope - neorg - plenary - nvim-treesitter - ]; - expectedParsers = [ "norg" "norg_meta" ]; - } - # 10. …with explicit parser request — should result in requested parser + ours (+ - # vim plugin deps as before)… - { - plugins = with pkgs.vimPlugins; [ - neorg-telescope - (nvim-treesitter.withPlugins (p: [ p.tree-sitter-bash ])) - ]; - expectedPluginFiles = with pluginMarkers; [ - telescope - neorg - plenary - nvim-treesitter - ]; - expectedParsers = [ "norg" "norg_meta" "bash" ]; - } - ]; + tests = let + pluginMarkers = { + neorg = "ftdetect/norg.vim"; + plenary = "plugin/plenary.vim"; + nvim-treesitter = "plugin/nvim-treesitter.lua"; + telescope = "plugin/telescope.lua"; + }; + in [ + { + # 1. Just neorg — should automatically pull in plugin and parser dependencies + plugins = with pkgs.vimPlugins; [neorg]; + expectedPluginFiles = with pluginMarkers; [neorg plenary nvim-treesitter]; + expectedParsers = [ + "norg" + "norg_meta" + ]; + } + # 2. Additional parser — should add to our parsers. + { + plugins = with pkgs.vimPlugins; [ + neorg + (nvim-treesitter.withPlugins (p: [p.tree-sitter-bash])) + ]; + expectedPluginFiles = with pluginMarkers; [neorg plenary nvim-treesitter]; + expectedParsers = ["bash" "norg" "norg_meta"]; + } + # 3. Requesting just norg parser — should add norg_meta parser. + { + plugins = with pkgs.vimPlugins; [ + neorg + (nvim-treesitter.withPlugins (p: [p.tree-sitter-norg])) + ]; + expectedPluginFiles = with pluginMarkers; [neorg plenary nvim-treesitter]; + expectedParsers = ["norg" "norg_meta"]; + } + # 4. Requesting norg and norg-meta parsers — shouldn't lead to duplicates (which + # would fail the derivation of the parser dir) + { + plugins = with pkgs.vimPlugins; [ + neorg + (nvim-treesitter.withPlugins + (p: [p.tree-sitter-norg p.tree-sitter-norg-meta])) + ]; + expectedPluginFiles = with pluginMarkers; [neorg plenary nvim-treesitter]; + expectedParsers = ["norg" "norg_meta"]; + } + # 5. Requesting norg and unrelated parser — should add norg-meta. + { + plugins = with pkgs.vimPlugins; [ + neorg + (nvim-treesitter.withPlugins (p: [p.tree-sitter-bash p.tree-sitter-norg])) + ]; + expectedPluginFiles = with pluginMarkers; [neorg plenary nvim-treesitter]; + expectedParsers = ["norg" "norg_meta" "bash"]; + } + # 6. withAllGrammars — should include our parsers… + { + plugins = with pkgs.vimPlugins; [neorg nvim-treesitter.withAllGrammars]; + expectedPluginFiles = with pluginMarkers; [neorg plenary nvim-treesitter]; + expectedParsers = [ + "norg" + "norg_meta" + # exemplary for "all": + "bash" + "perl" + ]; + } + # 7. …using allGrammars — as in 6. + { + plugins = with pkgs.vimPlugins; [ + neorg + (nvim-treesitter.withPlugins (_: nvim-treesitter.allGrammars)) + ]; + expectedPluginFiles = with pluginMarkers; [neorg plenary nvim-treesitter]; + expectedParsers = [ + "norg" + "norg_meta" + # exemplary for "all": + "bash" + "perl" + ]; + } + # 8. Requesting just neorg-telescope — should pull in all required vim plugins and + # our parsers… + { + plugins = with pkgs.vimPlugins; [neorg-telescope]; + expectedPluginFiles = with pluginMarkers; [ + telescope + neorg + plenary + nvim-treesitter + ]; + expectedParsers = ["norg" "norg_meta"]; + } + # 9. …with explicit neorg request — as in 8. … + { + plugins = with pkgs.vimPlugins; [neorg neorg-telescope]; + expectedPluginFiles = with pluginMarkers; [ + telescope + neorg + plenary + nvim-treesitter + ]; + expectedParsers = ["norg" "norg_meta"]; + } + # 10. …with explicit parser request — should result in requested parser + ours (+ + # vim plugin deps as before)… + { + plugins = with pkgs.vimPlugins; [ + neorg-telescope + (nvim-treesitter.withPlugins (p: [p.tree-sitter-bash])) + ]; + expectedPluginFiles = with pluginMarkers; [ + telescope + neorg + plenary + nvim-treesitter + ]; + expectedParsers = ["norg" "norg_meta" "bash"]; + } + ]; in -listToAttrs (imap - (i: test: rec { - name = "test${toString i}"; - value = makeTest (test // { inherit name; }); - }) - tests) + listToAttrs (imap + (i: test: rec { + name = "test${toString i}"; + value = makeTest (test // {inherit name;}); + }) + tests)