Skip to content

Commit 962df75

Browse files
committed
feat: check paths by type and plug in addon loader
refactor: compileLuarc uses install entries to more precisely control config edits, closes #24
1 parent e0a2828 commit 962df75

3 files changed

Lines changed: 431 additions & 146 deletions

File tree

spec/behavior_spec.lua

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@ local lfs = require("lfs") ---@type LuaFileSystem
22

33
local luarocks = {
44
---@type luarocks.core.cfg
5-
cfg = require("luarocks.core.cfg"),
6-
fs = require("luarocks.fs"),
7-
path = require("luarocks.path"),
5+
cfg = require("luarocks.core.cfg") --[[@as luarocks.core.cfg]],
6+
fs = require("luarocks.fs") --[[@as luarocks.fs]],
7+
path = require("luarocks.path") --[[@as luarocks.path]],
88
util = require("luarocks.util"),
99
cmd = {
1010
init = require("luarocks.cmd.init"),
1111
make = require("luarocks.cmd.make"),
1212
},
1313
}
1414

15+
require("luarocks.cmd.install") -- sets deps.installer
1516
local json = require("luarocks.build.lls-addon.json-util")
17+
local llsAddon = require("luarocks.build.lls-addon")
1618
local log = require("luarocks.build.lls-addon.log")
1719

1820
local upgradeFinally = require("spec.util.upgrade-finally")
1921

20-
assert(_VERSION == "Lua 5.4", "version is not Lua 5.4")
22+
local TARGET_VERSION = "5.4"
23+
assert(_VERSION == "Lua " .. TARGET_VERSION, "version is not Lua " .. TARGET_VERSION)
2124

2225
local SEP = package.config:sub(1, 1)
2326
---@param ... string
@@ -45,8 +48,9 @@ local function path(...)
4548
return table.concat(parts, SEP)
4649
end
4750

48-
local INSTALL_DIR = path("lua_modules", "lib", "luarocks", "rocks-5.4", "types", "0.1-1")
49-
local LUA_DIR = path("lua_modules", "share", "lua", "5.4")
51+
---@type "lua_modules/lib/luarocks/rocks-5.4/types/0.1-1"
52+
local INSTALL_DIR = path("lua_modules", "lib", "luarocks", "rocks-" .. TARGET_VERSION, "types", "0.1-1")
53+
local LUA_DIR = path("lua_modules", "share", "lua", TARGET_VERSION) ---@type "lua_modules/share/lua/5.4"
5054

5155
---@param path string
5256
---@return string? mode
@@ -153,6 +157,9 @@ local function pushDir(dirPath)
153157
end)
154158
end
155159

160+
---@type "path/to/lls-addon-loader.lua"
161+
local FAKE_LOADER_SOURCE = path("path", "to", "lls-addon-loader.lua")
162+
156163
---@param options? lls-addon.spec.makeProject.options
157164
local function makeProject(options)
158165
options = options or {}
@@ -166,6 +173,7 @@ local function makeProject(options)
166173
stub(luarocks.util, "printout")
167174
stub(luarocks.util, "warning")
168175
stub(luarocks.util, "printerr")
176+
stub(llsAddon, "getLoaderSource", FAKE_LOADER_SOURCE)
169177
local logMock = mock(log, --[[stub:]] true)
170178

171179
local oldProjectDir = luarocks.cfg.project_dir
@@ -251,7 +259,12 @@ describe("luarocks-build-lls-addon", function()
251259
assert.are_equal("file", mode(path(LUA_DIR, "types.lua")))
252260
local luarc = json.read(".luarc.json")
253261
assert.are_same({
254-
runtime = { plugin = path(LUA_DIR, "types.lua") },
262+
runtime = {
263+
plugin = {
264+
FAKE_LOADER_SOURCE,
265+
path(LUA_DIR, "types.lua"),
266+
},
267+
},
255268
}, luarc)
256269
end)
257270

@@ -273,7 +286,12 @@ describe("luarocks-build-lls-addon", function()
273286
local luarc = json.read(".luarc.json")
274287
assert.are_same({
275288
workspace = { library = { path(INSTALL_DIR, "library") } },
276-
runtime = { plugin = path(LUA_DIR, "types.lua") },
289+
runtime = {
290+
plugin = {
291+
FAKE_LOADER_SOURCE,
292+
path(LUA_DIR, "types.lua"),
293+
},
294+
},
277295
}, luarc)
278296
end)
279297

@@ -284,7 +302,12 @@ describe("luarocks-build-lls-addon", function()
284302
local luarc = json.read(".luarc.json")
285303
assert.are_same({
286304
example = true,
287-
runtime = { plugin = path(LUA_DIR, "types.lua") },
305+
runtime = {
306+
plugin = {
307+
FAKE_LOADER_SOURCE,
308+
path(LUA_DIR, "types.lua"),
309+
},
310+
},
288311
}, luarc)
289312
end)
290313

@@ -297,7 +320,12 @@ describe("luarocks-build-lls-addon", function()
297320
assert.are_same({
298321
workspace = { library = { path(INSTALL_DIR, "library") } },
299322
example = true,
300-
runtime = { plugin = path(LUA_DIR, "types.lua") },
323+
runtime = {
324+
plugin = {
325+
FAKE_LOADER_SOURCE,
326+
path(LUA_DIR, "types.lua"),
327+
},
328+
},
301329
}, luarc)
302330
end)
303331

@@ -371,7 +399,12 @@ describe("luarocks-build-lls-addon", function()
371399
assert.are_same({
372400
hover = { enable = true },
373401
workspace = { library = { path(cd, INSTALL_DIR, "library") } },
374-
runtime = { plugin = path(cd, LUA_DIR, "types.lua") },
402+
runtime = {
403+
plugin = {
404+
FAKE_LOADER_SOURCE,
405+
path(cd, LUA_DIR, "types.lua"),
406+
},
407+
},
375408
}, luarc)
376409
end)
377410

0 commit comments

Comments
 (0)