Files
hego.nvim/lua/hego/sdk.lua
T

103 lines
2.4 KiB
Lua

local M = {}
local function sdk(args, title)
local exec = require("hego.exec")
local cmd = vim.list_extend({ "nrfutil", "sdk-manager" }, args)
return exec.run_async(cmd, {
title = title or "hego://sdk-manager",
cwd = vim.fn.getcwd(),
})
end
--- Salida de `sdk-manager list` (nrfutil 8.2.1):
--- SDK Type SDK Version SDK Status Toolchain Status
--- nrf v3.4.1 Not installed Installed
function M.list()
local out = vim.fn.system({ "nrfutil", "sdk-manager", "list" })
if vim.v.shell_error ~= 0 then
return {}
end
local sdks = {}
for _, line in ipairs(vim.split(out, "\n", { plain = true })) do
local typ, version, status, tc =
line:match("^(%S+)%s+(v[%d%.]+)%s+(Not installed|Installed)%s+(Not installed|Installed)%s*$")
if typ and version then
table.insert(sdks, {
type = typ,
version = version,
installed = status == "Installed",
toolchain = tc == "Installed",
})
end
end
return sdks
end
function M.search()
sdk({ "search" }, "hego://sdk-search")
end
--- `install` toma la versión POSICIONAL (verificado: <VERSION>, con 'v').
function M.install(version)
version = version and vim.trim(version) or ""
if version == "" then
return
end
sdk({ "install", version }, "hego://sdk-install")
end
function M.install_prompt(opts)
vim.ui.input({
prompt = "Versión de SDK a instalar (p.ej. v3.4.1): ",
default = opts.ncs_version or "",
}, function(input)
if input and vim.trim(input) ~= "" then
M.install(vim.trim(input))
end
end)
end
--- <leader>ns: picker con el estado real de SDKs y toolchains.
function M.pick(opts)
local sdks = M.list()
if #sdks == 0 then
-- Sin parseo posible: cae al modo volcado.
return sdk({ "list" }, "hego://sdk-list")
end
vim.ui.select(sdks, {
prompt = "SDK (fuente)",
format_item = function(s)
return string.format(
"%s %-8s sdk:%-14s toolchain:%s",
s.type,
s.version,
s.installed and "installed" or "not installed",
s.toolchain and "installed" or "not installed"
)
end,
}, function(choice)
if not choice then
return
end
if choice.installed then
vim.notify("[hego] SDK " .. choice.version .. " ya instalado", vim.log.levels.INFO)
return
end
local ok = vim.fn.confirm(
("Instalar el SDK %s (árbol de fuentes, ~15 GB).\n¿Seguir?"):format(choice.version),
"&Sí\n&No",
2
)
if ok == 1 then
M.install(choice.version)
end
end)
end
return M