Skip to content

Commit

Permalink
fix: support raw init modname / fnl/init.fnl
Browse files Browse the repository at this point in the history
  • Loading branch information
rktjmp committed Jan 17, 2024
1 parent 0d0f414 commit 9d40515
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
6 changes: 4 additions & 2 deletions fnl/hotpot/loader/record/module.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
src-path (vim.fs.normalize src-path)
prefix-length (length prefix)
extension-length (length extension)
true-modname (let [src-init? (not= nil (string.find src-path "/init%....$")) ;; TODO: x.tl will fail here
mod-init? (not= nil (string.find modname "%.init$"))]
;; Expand `mod` into `mod.init` to match the source file if needed.
true-modname (let [src-init? (not= nil (string.find src-path (.. "/init%." extension "$")))
mod-init? (or (= :init modname)
(not= nil (string.find modname "%.init$")))]
(if (and src-init? (not mod-init?))
(.. modname ".init")
modname))
Expand Down
8 changes: 3 additions & 5 deletions lua/hotpot/loader/record/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ local function new(modname, src_path, _2_)
local extension_length = #extension
local true_modname
do
local src_init_3f = (nil ~= string.find(src_path0, "/init%....$"))
local mod_init_3f = (nil ~= string.find(modname, "%.init$"))
local src_init_3f = (nil ~= string.find(src_path0, ("/init%." .. extension .. "$")))
local mod_init_3f = (("init" == modname) or (nil ~= string.find(modname, "%.init$")))
if (src_init_3f and not mod_init_3f) then
true_modname = (modname .. ".init")
else
Expand Down Expand Up @@ -67,11 +67,9 @@ local function retarget(record, target)
elseif (target == "cache") then
record["lua-path"] = record["lua-cache-path"]
return record
elseif true then
else
local _ = target
return error("target must be colocate or cache")
else
return nil
end
end
local function _11_(_241)
Expand Down
11 changes: 9 additions & 2 deletions test/test-require-a-fnl-file.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@

(test-path :abc :abc) ;; basic
(test-path :def :def/init)
(test-path :def.init :def/init)
(test-path :xyz.init "xyz/init")
(test-path :abc.xyz.p-q-r :abc/xyz/p-q-r) ;; user issue 53, kebab files
(test-path :xc-init :xc-init) ;; user issue 53, kebab files
;; user issue 53, kebab files
(test-path :abc.xyz.p-q-r :abc/xyz/p-q-r)
(test-path :xc-init :xc-init)
;; issues/129
(test-path :init :init)
(test-path :fnl :fnl/init)
(test-path :some.code.fnl :some/code/fnl/init)
(test-path :some.code.fnl.init :some/code/fnl/init)

(exit)
37 changes: 15 additions & 22 deletions test/test-require-a-fnl-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,73 +56,66 @@ local function test_path(modname, path)
local _9_ = ...
if (_9_ == true) then
return true
elseif true then
local __75_auto = _9_
return ...
else
return nil
local __84_auto = _9_
return ...
end
end
local function _12_(...)
local _11_ = read_file(lua_path)
if (_11_ == "return {works = true}") then
OK(string.format(("Outputs correct lua code" or "")))
return true
elseif true then
else
local __1_auto = _11_
FAIL(string.format(("Outputs correct lua code" or "")))
return false
else
return nil
end
end
return _8_(_12_(...))
elseif true then
local __75_auto = _7_
return ...
else
return nil
local __84_auto = _7_
return ...
end
end
local function _16_(...)
local _15_ = vim.loop.fs_access(lua_path, "R")
if (_15_ == true) then
OK(string.format(("Creates a lua file at %s" or ""), lua_path))
return true
elseif true then
else
local __1_auto = _15_
FAIL(string.format(("Creates a lua file at %s" or ""), lua_path))
return false
else
return nil
end
end
return _6_(_16_(...))
elseif true then
local __75_auto = _5_
return ...
else
return nil
local __84_auto = _5_
return ...
end
end
local function _21_()
local _19_, _20_ = pcall(require, modname)
if ((_19_ == true) and ((_G.type(_20_) == "table") and ((_20_).works == true))) then
if ((_19_ == true) and ((_G.type(_20_) == "table") and (_20_.works == true))) then
OK(string.format(("Can require module %s %s" or ""), modname, fnl_path))
return true
elseif true then
else
local __1_auto = _19_
FAIL(string.format(("Can require module %s %s" or ""), modname, fnl_path))
return false
else
return nil
end
end
return _4_(_21_())
end
test_path("abc", "abc")
test_path("def", "def/init")
test_path("def.init", "def/init")
test_path("xyz.init", "xyz/init")
test_path("abc.xyz.p-q-r", "abc/xyz/p-q-r")
test_path("xc-init", "xc-init")
test_path("init", "init")
test_path("fnl", "fnl/init")
test_path("some.code.fnl", "some/code/fnl/init")
test_path("some.code.fnl.init", "some/code/fnl/init")
return exit()

0 comments on commit 9d40515

Please sign in to comment.