mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-20 05:16:45 +00:00
fix(rocks): better errors / warnings when something goes wrong with luarocks
This commit is contained in:
parent
9005e8ede7
commit
7d3f69104f
11 changed files with 336 additions and 141 deletions
|
@ -12,6 +12,7 @@ local Process = require("lazy.manage.process")
|
|||
---@field output string
|
||||
---@field status string
|
||||
---@field error? string
|
||||
---@field warn? string
|
||||
---@field private _task fun(task:LazyTask)
|
||||
---@field private _running LazyPluginState[]
|
||||
---@field private _started? number
|
||||
|
@ -74,6 +75,30 @@ function Task:start()
|
|||
self:_check()
|
||||
end
|
||||
|
||||
---@param msg string|string[]
|
||||
---@param severity? vim.diagnostic.Severity
|
||||
function Task:notify(msg, severity)
|
||||
local var = severity == vim.diagnostic.severity.ERROR and "error"
|
||||
or severity == vim.diagnostic.severity.WARN and "warn"
|
||||
or "output"
|
||||
msg = type(msg) == "table" and table.concat(msg, "\n") or msg
|
||||
---@cast msg string
|
||||
---@diagnostic disable-next-line: no-unknown
|
||||
self[var] = self[var] and (self[var] .. "\n" .. msg) or msg
|
||||
self.status = msg
|
||||
vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false })
|
||||
end
|
||||
|
||||
---@param msg string|string[]
|
||||
function Task:notify_error(msg)
|
||||
self:notify(msg, vim.diagnostic.severity.ERROR)
|
||||
end
|
||||
|
||||
---@param msg string|string[]
|
||||
function Task:notify_warn(msg)
|
||||
self:notify(msg, vim.diagnostic.severity.WARN)
|
||||
end
|
||||
|
||||
---@param fn async fun()
|
||||
function Task:async(fn)
|
||||
local co = coroutine.create(fn)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
local Config = require("lazy.core.config")
|
||||
local Loader = require("lazy.core.loader")
|
||||
local Rocks = require("lazy.pkg.rockspec")
|
||||
local Util = require("lazy.util")
|
||||
|
||||
---@type table<string, LazyTaskDef>
|
||||
|
@ -16,52 +17,6 @@ end
|
|||
|
||||
local B = {}
|
||||
|
||||
---@param task LazyTask
|
||||
function B.rockspec(task)
|
||||
---@type table<string, string>
|
||||
local env = {}
|
||||
|
||||
local luarocks = "luarocks"
|
||||
if Config.options.rocks.hererocks then
|
||||
local is_win = jit.os:find("Windows")
|
||||
local sep = is_win and ";" or ":"
|
||||
local hererocks = Config.options.rocks.root .. "/hererocks/bin"
|
||||
if is_win then
|
||||
hererocks = hererocks:gsub("/", "\\")
|
||||
end
|
||||
local path = vim.split(vim.env.PATH, sep)
|
||||
table.insert(path, 1, hererocks)
|
||||
env = {
|
||||
PATH = table.concat(path, sep),
|
||||
}
|
||||
if is_win then
|
||||
luarocks = luarocks .. ".bat"
|
||||
end
|
||||
local plugin = Config.plugins.hererocks
|
||||
-- hererocks is still building, so skip for now
|
||||
if plugin and plugin._.build then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local root = Config.options.rocks.root .. "/" .. task.plugin.name
|
||||
task:spawn(luarocks, {
|
||||
args = {
|
||||
"--tree",
|
||||
root,
|
||||
"--server",
|
||||
Config.options.rocks.server,
|
||||
"--dev",
|
||||
"--lua-version",
|
||||
"5.1",
|
||||
"make",
|
||||
"--force-fast",
|
||||
},
|
||||
cwd = task.plugin.dir,
|
||||
env = env,
|
||||
})
|
||||
end
|
||||
|
||||
---@param task LazyTask
|
||||
---@param build string
|
||||
function B.cmd(task, build)
|
||||
|
@ -114,7 +69,7 @@ M.build = {
|
|||
build(self.plugin)
|
||||
end)
|
||||
elseif build == "rockspec" then
|
||||
B.rockspec(self)
|
||||
Rocks.build(self)
|
||||
elseif build:sub(1, 1) == ":" then
|
||||
B.cmd(self, build)
|
||||
elseif build:match("%.lua$") then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue