diff --git a/.github/workflows/docgen.yml b/.github/workflows/docgen.yml deleted file mode 100644 index 786ad05..0000000 --- a/.github/workflows/docgen.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -name: Generate docs - -on: - push: - branches-ignore: - - master - -jobs: - docs: - name: Generate docs - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v23 - - uses: cachix/cachix-action@v12 - with: - name: neorocks - authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - - - name: Generating docs - run: nix run ".#docgen" - - - name: Update documentation - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COMMIT_MSG: | - docs(generated): update doc/rocks.txt - skip-checks: true - run: | - git config user.email "actions@github" - git config user.name "Github Actions" - git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git - git add doc/ - # Only commit and push if we have changes - git diff --quiet && git diff --staged --quiet || (git commit -m "${COMMIT_MSG}"; git push origin HEAD:${GITHUB_REF}) diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index 98f8663..6b0f494 100755 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -6,6 +6,6 @@ jobs: checks: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: cachix/install-nix-action@v20 + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v9 - run: nix flake check -L diff --git a/flake.lock b/flake.lock index 90d658b..bfdde1c 100755 --- a/flake.lock +++ b/flake.lock @@ -103,11 +103,11 @@ "nixpkgs-lib": "nixpkgs-lib_2" }, "locked": { - "lastModified": 1715865404, - "narHash": "sha256-/GJvTdTpuDjNn84j82cU6bXztE0MSkdnTWClUCRub78=", + "lastModified": 1717285511, + "narHash": "sha256-iKzJcpdXih14qYVcZ9QC9XuZYnPc6T8YImb6dX166kw=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "8dc45382d5206bd292f9c2768b8058a8fd8311d9", + "rev": "2a55567fcf15b1b1c7ed712a2c6fadaec7412ea8", "type": "github" }, "original": { @@ -184,11 +184,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1717108591, - "narHash": "sha256-Sn6jrh9Nqp5UKJzNT0rg/DQCJCpFs/d+RM2/iENPpBo=", + "lastModified": 1718922730, + "narHash": "sha256-ykhhOPqA9NzdNBr3ii+3h2DkK2+wasNqQLfMF6BXxTE=", "owner": "mrcjkb", "repo": "nix-gen-luarc-json", - "rev": "39704e58b5227a82a14a00f5912e4bfccfa2b687", + "rev": "021e8078e43884c6cdc70ca753d9a0b146cd55a4", "type": "github" }, "original": { @@ -205,11 +205,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1716213921, - "narHash": "sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA=", + "lastModified": 1719259945, + "narHash": "sha256-F1h+XIsGKT9TkGO3omxDLEb/9jOOsI6NnzsXFsZhry4=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "0e8fcc54b842ad8428c9e705cb5994eaf05c26a0", + "rev": "0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07", "type": "github" }, "original": { @@ -234,11 +234,11 @@ ] }, "locked": { - "lastModified": 1716213921, - "narHash": "sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA=", + "lastModified": 1719259945, + "narHash": "sha256-F1h+XIsGKT9TkGO3omxDLEb/9jOOsI6NnzsXFsZhry4=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "0e8fcc54b842ad8428c9e705cb5994eaf05c26a0", + "rev": "0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07", "type": "github" }, "original": { @@ -323,11 +323,11 @@ ] }, "locked": { - "lastModified": 1713898448, - "narHash": "sha256-6q6ojsp/Z9P2goqnxyfCSzFOD92T3Uobmj8oVAicUOs=", + "lastModified": 1719226092, + "narHash": "sha256-YNkUMcCUCpnULp40g+svYsaH1RbSEj6s4WdZY/SHe38=", "owner": "hercules-ci", "repo": "hercules-ci-effects", - "rev": "c0302ec12d569532a6b6bd218f698bc402e93adc", + "rev": "11e4b8dc112e2f485d7c97e1cee77f9958f498f5", "type": "github" }, "original": { @@ -345,11 +345,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1717565085, - "narHash": "sha256-4d7VaRRjKGbFkam+65fb8Qll6lu/3NURfrngqjgJeCo=", + "lastModified": 1719552233, + "narHash": "sha256-srQ8MbcPgXrQj2xywQLKy/p/x+kFYStUhdNhFK2pZL0=", "owner": "nvim-neorocks", "repo": "neorocks", - "rev": "cd9580a8997a5b7a9d5b009ee40c739c1512574d", + "rev": "8c01ff3cba17c57271a0a55558ee9c93fe0f0ea1", "type": "github" }, "original": { @@ -368,11 +368,11 @@ "nixpkgs": "nixpkgs_3" }, "locked": { - "lastModified": 1717559432, - "narHash": "sha256-UkjZp5LfrWKxidGzZLRqHs3H4/u6FQAc5yS5QsLKndw=", + "lastModified": 1719467057, + "narHash": "sha256-8gQ0txwuLoBpBeIhTAkl+/7Hi/AD4KE5m4YhOn1OA3E=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "52dd6362442d42dfc0d2f7c0176690d64ba4fc6d", + "rev": "bb6bea003dc464a4248a173e71a007d368691092", "type": "github" }, "original": { @@ -384,11 +384,11 @@ "neovim-src": { "flake": false, "locked": { - "lastModified": 1717536944, - "narHash": "sha256-JzJ3xxXmI8732nl3p2Zg/qZiaLTVEWZ8pn3PfsGnvxs=", + "lastModified": 1719414226, + "narHash": "sha256-h/qJ+1R+BtY+mX02UsqYW82hEl78mrHTGAs9yjpFEzU=", "owner": "neovim", "repo": "neovim", - "rev": "f69937fdbd162630c35e119e67bbbf052558c0e0", + "rev": "fc9b70826ec88ca2e6c0624c522b872e87aa7ac1", "type": "github" }, "original": { @@ -399,11 +399,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1716948383, - "narHash": "sha256-SzDKxseEcHR5KzPXLwsemyTR/kaM9whxeiJohbL04rs=", + "lastModified": 1718714799, + "narHash": "sha256-FUZpz9rg3gL8NVPKbqU8ei1VkPLsTIfAJ2fdAf5qjak=", "owner": "nixos", "repo": "nixpkgs", - "rev": "ad57eef4ef0659193044870c731987a6df5cf56b", + "rev": "c00d587b1a1afbf200b1d8f0b0e4ba9deb1c7f0e", "type": "github" }, "original": { @@ -427,14 +427,14 @@ }, "nixpkgs-lib_2": { "locked": { - "lastModified": 1714640452, - "narHash": "sha256-QBx10+k6JWz6u7VsohfSw8g8hjdBZEf8CFzXH1/1Z94=", + "lastModified": 1717284937, + "narHash": "sha256-lIbdfCsf8LMFloheeE6N31+BMIeixqyQWbSr2vk79EQ=", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" }, "original": { "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" } }, "nixpkgs-lib_3": { @@ -451,11 +451,11 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1710695816, - "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "lastModified": 1718811006, + "narHash": "sha256-0Y8IrGhRmBmT7HHXlxxepg2t8j1X90++qRN3lukGaIk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "rev": "03d771e513ce90147b65fe922d87d3a0356fc125", "type": "github" }, "original": { @@ -467,11 +467,11 @@ }, "nixpkgs-stable_2": { "locked": { - "lastModified": 1710695816, - "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "lastModified": 1718811006, + "narHash": "sha256-0Y8IrGhRmBmT7HHXlxxepg2t8j1X90++qRN3lukGaIk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "rev": "03d771e513ce90147b65fe922d87d3a0356fc125", "type": "github" }, "original": { @@ -483,11 +483,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1710765496, - "narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=", + "lastModified": 1719082008, + "narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7", + "rev": "9693852a2070b398ee123a329e68f0dab5526681", "type": "github" }, "original": { @@ -499,11 +499,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1717399147, - "narHash": "sha256-eCWaE/q1VItpFAxxLVt171MdtDcjEnwi6QB/yuF73JU=", + "lastModified": 1719379843, + "narHash": "sha256-u+D+IOAMMl70+CJ9NKB+RMrASjInuIWMHzjLWQjPZ6c=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4a4ecb0ab415c9fccfb005567a215e6a9564cdf5", + "rev": "b3f3c1b13fb08f3828442ee86630362e81136bbc", "type": "github" }, "original": { @@ -515,11 +515,11 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1717399147, - "narHash": "sha256-eCWaE/q1VItpFAxxLVt171MdtDcjEnwi6QB/yuF73JU=", + "lastModified": 1719468428, + "narHash": "sha256-vN5xJAZ4UGREEglh3lfbbkIj+MPEYMuqewMn4atZFaQ=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4a4ecb0ab415c9fccfb005567a215e6a9564cdf5", + "rev": "1e3deb3d8a86a870d925760db1a5adecc64d329d", "type": "github" }, "original": { @@ -531,11 +531,11 @@ }, "nixpkgs_5": { "locked": { - "lastModified": 1717399147, - "narHash": "sha256-eCWaE/q1VItpFAxxLVt171MdtDcjEnwi6QB/yuF73JU=", + "lastModified": 1719468428, + "narHash": "sha256-vN5xJAZ4UGREEglh3lfbbkIj+MPEYMuqewMn4atZFaQ=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4a4ecb0ab415c9fccfb005567a215e6a9564cdf5", + "rev": "1e3deb3d8a86a870d925760db1a5adecc64d329d", "type": "github" }, "original": { @@ -547,11 +547,11 @@ }, "nixpkgs_6": { "locked": { - "lastModified": 1710765496, - "narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=", + "lastModified": 1719082008, + "narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7", + "rev": "9693852a2070b398ee123a329e68f0dab5526681", "type": "github" }, "original": { @@ -569,11 +569,11 @@ "nixpkgs-stable": "nixpkgs-stable_2" }, "locked": { - "lastModified": 1716213921, - "narHash": "sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA=", + "lastModified": 1719259945, + "narHash": "sha256-F1h+XIsGKT9TkGO3omxDLEb/9jOOsI6NnzsXFsZhry4=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "0e8fcc54b842ad8428c9e705cb5994eaf05c26a0", + "rev": "0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 0999b63..4c1def3 100755 --- a/flake.nix +++ b/flake.nix @@ -61,7 +61,6 @@ luarc = pkgs.mk-luarc { nvim = pkgs.neovim-nightly; - neodev-types = "nightly"; }; type-check-nightly = pre-commit-hooks.lib.${system}.run { @@ -90,7 +89,7 @@ }; }; - devShell = pkgs.nvim-nightly-tests.overrideAttrs (oa: { + devShell = pkgs.mkShell { name = "lz.n devShell"; shellHook = '' ${pre-commit-check.shellHook} @@ -98,11 +97,11 @@ ''; buildInputs = self.checks.${system}.pre-commit-check.enabledPackages - ++ oa.buildInputs ++ (with pkgs; [ lua-language-server + busted-nlua ]); - }); + }; in { devShells = { default = devShell; @@ -113,7 +112,6 @@ default = lz-n-vimPlugin; lz-n-luaPackage = pkgs.lua51Packages.lz-n; lz-n-vimPlugin = pkgs.vimPlugins.lz-n; - inherit (pkgs) docgen; }; checks = { diff --git a/lua/lz/n/handler/keys.lua b/lua/lz/n/handler/keys.lua index 4c5d6fd..244fde7 100644 --- a/lua/lz/n/handler/keys.lua +++ b/lua/lz/n/handler/keys.lua @@ -2,30 +2,44 @@ local loader = require("lz.n.loader") ---@class lz.n.KeysHandler: lz.n.Handler +---@param value lz.n.KeysSpec +---@param mode? string +---@return lz.n.Keys +local function parse(value, mode) + local ret = vim.deepcopy(value) --[[@as lz.n.Keys]] + ret.lhs = ret[1] or "" + ret.rhs = ret[2] + ret[1] = nil + ret[2] = nil + ret.mode = mode or "n" + ret.id = vim.api.nvim_replace_termcodes(ret.lhs, true, true, true) + if ret.ft then + local ft = type(ret.ft) == "string" and { ret.ft } or ret.ft --[[@as string[] ]] + ret.id = ret.id .. " (" .. table.concat(ft, ", ") .. ")" + end + if ret.mode ~= "n" then + ret.id = ret.id .. " (" .. ret.mode .. ")" + end + return ret +end + ---@type lz.n.KeysHandler local M = { pending = {}, spec_field = "keys", ---@param value string|lz.n.KeysSpec - ---@param mode? string - ---@return lz.n.Keys - parse = function(value, mode) + ---@return lz.n.Keys[] + parse = function(value) value = type(value) == "string" and { value } or value --[[@as lz.n.KeysSpec]] - local ret = vim.deepcopy(value) --[[@as lz.n.Keys]] - ret.lhs = ret[1] or "" - ret.rhs = ret[2] - ret[1] = nil - ret[2] = nil - ret.mode = mode or "n" - ret.id = vim.api.nvim_replace_termcodes(ret.lhs, true, true, true) - if ret.ft then - local ft = type(ret.ft) == "string" and { ret.ft } or ret.ft --[[@as string[] ]] - ret.id = ret.id .. " (" .. table.concat(ft, ", ") .. ")" + local modes = type(value.mode) == "string" and { value.mode } or value.mode --[[ @as string[] | nil ]] + if not modes then + return { parse(value) } end - if ret.mode ~= "n" then - ret.id = ret.id .. " (" .. ret.mode .. ")" - end - return ret + return vim.iter(modes) + :map(function(mode) + return parse(value, mode) + end) + :totable() end, } diff --git a/lua/lz/n/spec.lua b/lua/lz/n/spec.lua index fc3e1e5..0880c61 100644 --- a/lua/lz/n/spec.lua +++ b/lua/lz/n/spec.lua @@ -115,12 +115,12 @@ local function parse(spec) end if type(keys_spec) == "string" then local keys = require("lz.n.handler.keys").parse(keys_spec) - table.insert(result.keys, keys) + vim.list_extend(result.keys, keys) elseif type(keys_spec) == "table" then ---@param keys_spec_ string | lz.n.KeysSpec vim.iter(keys_spec):each(function(keys_spec_) local keys = require("lz.n.handler.keys").parse(keys_spec_) - table.insert(result.keys, keys) + vim.list_extend(result.keys, keys) end) end local cmd_spec = spec.cmd diff --git a/nix/ci-overlay.nix b/nix/ci-overlay.nix index 469029f..d172b26 100755 --- a/nix/ci-overlay.nix +++ b/nix/ci-overlay.nix @@ -40,22 +40,10 @@ with final.stdenv; let cp -r tests $out ''; }; - - docgen = final.writeShellApplication { - name = "docgen"; - runtimeInputs = with final; [ - lemmy-help - ]; - text = '' - mkdir -p doc - lemmy-help lua/lz/n/{init,commands,config/init}.lua > doc/lz.n.txt - ''; - }; in { nvim-stable-tests = mkNeorocksTest {name = "neovim-stable-tests";}; nvim-nightly-tests = mkNeorocksTest { name = "neovim-nightly-tests"; nvim = nvim-nightly; }; - inherit docgen; } diff --git a/spec/keys_spec.lua b/spec/keys_spec.lua index b4d442b..ad59456 100644 --- a/spec/keys_spec.lua +++ b/spec/keys_spec.lua @@ -16,9 +16,9 @@ describe("handlers.keys", function() } for _, test in ipairs(tests) do if test[3] then - assert.same(keys.parse(test[1]).id, keys.parse(test[2]).id) + assert.same(keys.parse(test[1])[1].id, keys.parse(test[2])[1].id) else - assert.is_not.same(keys.parse(test[1]).id, keys.parse(test[2]).id) + assert.is_not.same(keys.parse(test[1])[1].id, keys.parse(test[2])[1].id) end end end) @@ -27,7 +27,7 @@ describe("handlers.keys", function() ---@type lz.n.Plugin local plugin = { name = "foo", - keys = { keys.parse(lhs) }, + keys = keys.parse(lhs), } local spy_load = spy.on(loader, "_load") state.plugins[plugin.name] = plugin @@ -55,15 +55,15 @@ describe("handlers.keys", function() vim.api.nvim_feedkeys(feed2, "ix", false) assert.spy(spy_load).called(1) end - itt({ keys.parse("tt"), keys.parse("ff") }) - itt({ keys.parse("ff"), keys.parse("tt") }) + itt({ keys.parse("tt")[1], keys.parse("ff")[1] }) + itt({ keys.parse("ff")[1], keys.parse("tt")[1] }) end) it("Plugins' keymaps are triggered", function() local lhs = "xy" ---@type lz.n.Plugin local plugin = { name = "baz", - keys = { keys.parse(lhs) }, + keys = keys.parse(lhs), } local triggered = false local orig_load = loader._load diff --git a/spec/lz_n_spec.lua b/spec/lz_n_spec.lua index afcd03b..66b87a3 100644 --- a/spec/lz_n_spec.lua +++ b/spec/lz_n_spec.lua @@ -19,7 +19,7 @@ describe("lz.n", function() }, { "telescope.nvim", - keys = "tt", + keys = { { "tt", mode = { "n", "v" } } }, cmd = "Telescope", }, }) @@ -44,7 +44,10 @@ describe("lz.n", function() name = "telescope.nvim", lazy = true, cmd = { "Telescope" }, - keys = { require("lz.n.handler.keys").parse("tt") }, + keys = { + { id = "\\tt", lhs = "tt", mode = "n" }, + { id = "\\tt (v)", lhs = "tt", mode = "v" }, + }, }) end) it("individual plugin specs", function()