Skip to content

Commit 47c93a7

Browse files
committed
feat: add module luarocks.lls-addon-loader
1 parent 4b0eac6 commit 47c93a7

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

.luarc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
"lua_modules/share/lua/5.4/?.lua",
1212
"lua_modules/share/lua/5.4/?/init.lua"
1313
],
14-
"version": "Lua 5.4"
14+
"version": "Lua 5.5",
15+
"plugin": ["./lua_modules/share/lua/5.5/luarocks/lls-addon-loader.lua"]
1516
},
1617
"workspace": {
1718
"checkThirdParty": false,
1819
"library": [
1920
"${addons}/luafilesystem/module/library",
2021
"${addons}/busted/module/library",
2122
"${addons}/luassert/module/library",
22-
"$USERPROFILE/Documents/References/luarocks/src"
23+
"$USERPROFILE/Documents/References/luarocks/src",
24+
"types"
2325
]
2426
}
2527
}

src/luarocks/lls-addon-loader.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local thisFunction = ...
2+
assert(type(thisFunction) == "function", "must be loaded as a plugin from lua-language-server")
3+
4+
local fs = require("bee.filesystem")
5+
local furi = require("file-uri")
6+
local workspace = require("workspace")
7+
8+
local start, _, dir_sep = string.find(package.path, "([/\\])luarocks%1%?%.lua$")
9+
assert(start, "could not replace path")
10+
package.path = string.sub(package.path, 1, start - 1) .. dir_sep .. "?.lua"
11+
12+
local cfg = require("luarocks.core.cfg") --[[@as luarocks.core.cfg]]
13+
require("luarocks.loader")
14+
15+
local workspaceRoot = fs.path(furi.decode(workspace.rootUri))
16+
local lua_modules = workspaceRoot / "lua_modules"
17+
if fs.exists(lua_modules:string()) then
18+
print("luarocks-build-lls-addon: configured workspace as project directory")
19+
-- re-initialize cfg with the project directory (loads in the project config from ./.luarocks)
20+
cfg.init({ project_dir = workspaceRoot:string() })
21+
-- add ./lua_modules as one of the queryable rocks trees
22+
table.insert(cfg.rocks_trees, 1, { name = "project", root = lua_modules:string() } --[[@as luarocks.core.Tree]])
23+
end
24+
25+
print("luarocks-build-lls-addon: loader finished!")

0 commit comments

Comments
 (0)