From fa625dd86414dc830c6c9b7188fe4cd583e664c4 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Wed, 19 Jun 2024 17:48:15 +0200 Subject: [PATCH] fix: support /nix/store links --- lua/lz/n/spec.lua | 8 ++++++-- spec/import_spec.lua | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lua/lz/n/spec.lua b/lua/lz/n/spec.lua index 33206e0..c1f72b1 100644 --- a/lua/lz/n/spec.lua +++ b/lua/lz/n/spec.lua @@ -59,9 +59,13 @@ local function import_spec(spec, result) ty = ty or vim.uv.fs_stat(path).type if not name then break - elseif ty == "file" or ty == "directory" then - local submodname = vim.fn.fnamemodify(name, ":r") + -- XXX: "link" is required to support Nix. + -- It seems to break in tests with with local symlinks + elseif (ty == "file" or ty == "link") and name:sub(-4) == ".lua" then + local submodname = name:sub(1, -5) import_modname(modname .. "." .. submodname, result) + elseif ty == "directory" and vim.uv.fs_stat(vim.fs.joinpath(path, "init.lua")) then + import_modname(modname .. "." .. name, result) end end end diff --git a/spec/import_spec.lua b/spec/import_spec.lua index e49d37e..af99d07 100644 --- a/spec/import_spec.lua +++ b/spec/import_spec.lua @@ -49,6 +49,7 @@ describe("lz.n", function() vim.system({ "rm", plugin1_spec_file }):wait() end) it("import plugin specs and spec file", function() + local plugins_dir = vim.fs.joinpath(tempdir, "lua", "plugins") local plugin1_config_content = [[ return { "telescope.nvim", @@ -58,7 +59,7 @@ return { end, } ]] - local spec_file = vim.fs.joinpath(tempdir, "lua", "plugins", "telescope.lua") + local spec_file = vim.fs.joinpath(plugins_dir, "telescope.lua") local fh = assert(io.open(spec_file, "w"), "Could not open config file for writing") fh:write(plugin1_config_content) fh:close() @@ -71,12 +72,24 @@ return { end, } ]] - local plugin2_dir = vim.fs.joinpath(tempdir, "lua", "plugins", "foo") + local plugin2_dir = vim.fs.joinpath(plugins_dir, "foo") vim.system({ "mkdir", "-p", plugin2_dir }):wait() local plugin2_spec_file = vim.fs.joinpath(plugin2_dir, "init.lua") fh = assert(io.open(plugin2_spec_file, "w"), "Could not open config file for writing") fh:write(plugin2_config_content) fh:close() + -- FIXME: This fails here, but works with Nix links + -- local plugin3_config_content = [[ + -- return { + -- "linked.nvim", + -- cmd = "Linked", + -- } + -- ]] + -- local plugin3_spec_file = vim.fs.joinpath(tempdir, "linked.lua") + -- fh = assert(io.open(spec_file, "w"), "Could not open config file for writing") + -- fh:write(plugin3_config_content) + -- fh:close() + -- vim.uv.fs_symlink(plugin3_spec_file, vim.fs.joinpath(plugins_dir, "linked.lua")) vim.opt.runtimepath:append(tempdir) local spy_load = spy.on(loader, "_load") lz.load({ @@ -90,6 +103,8 @@ return { vim.cmd.Foo() assert.spy(spy_load).called(3) assert.True(vim.g.foo_after) + vim.cmd.Linked() + -- assert.spy(spy_load).called(4) vim.system({ "rm", plugin2_spec_file }):wait() end) end)