diff --git a/lua/hego/commands.lua b/lua/hego/commands.lua index 19acd94..45ff90b 100644 --- a/lua/hego/commands.lua +++ b/lua/hego/commands.lua @@ -1,14 +1,41 @@ local M = {} function M.setup(_) - vim.api.nvim_create_user_command("HegoBuild", function() - require("hego").build(false) + local H = require("hego") + local cmd = vim.api.nvim_create_user_command + + cmd("HegoBuild", function() + H.build(false) end, {}) - vim.api.nvim_create_user_command("HegoBuildPristine", function() - require("hego").build(true) + cmd("HegoBuildPristine", function() + H.build(true) end, {}) - vim.api.nvim_create_user_command("HegoFlash", function() - require("hego").flash() + cmd("HegoFlash", function() + H.flash() + end, {}) + cmd("HegoFlashErase", function() + H.flash("erase") + end, {}) + cmd("HegoFlashRecover", function() + H.flash("recover") + end, {}) + cmd("HegoDeviceRecover", function() + H.device_recover() + end, {}) + cmd("HegoMenuconfig", function() + H.kconfig() + end, {}) + cmd("HegoMemoryReport", function() + H.memory_report() + end, {}) + cmd("HegoMonitor", function() + H.monitor() + end, {}) + cmd("HegoConfig", function() + H.edit_config() + end, {}) + cmd("HegoBuildConfig", function() + H.build_from_config() end, {}) end diff --git a/lua/hego/config.lua b/lua/hego/config.lua new file mode 100644 index 0000000..e59b544 --- /dev/null +++ b/lua/hego/config.lua @@ -0,0 +1,137 @@ +local M = {} + +M.path = ".hego/configs.json" + +-- Valores "de máquina" para los enums (los labels son solo presentación). +M.sysbuild_choices = { + { label = "Build system default", value = "default" }, + { label = "Use sysbuild", value = "yes" }, + { label = "No sysbuild", value = "no" }, +} + +M.optimization_choices = { + { label = "Project default", value = "default" }, + { label = "Optimize for size", value = "size" }, + { label = "Optimize for speed", value = "speed" }, + { label = "Optimize for debugging", value = "debug" }, +} + +M.default_config = { + board = nil, + conf_files = {}, + extra_conf_files = {}, + overlays = {}, + extra_overlays = {}, + snippets = {}, + optimization = "default", + debug_thread_info = false, + extra_cmake = {}, + build_dir = "build", + generate_only = false, + sysbuild = "default", +} + +local ARRAY_FIELDS = { + "conf_files", + "extra_conf_files", + "overlays", + "extra_overlays", + "snippets", + "extra_cmake", +} + +--- Rellena huecos con los defaults y garantiza que los campos lista son listas. +--- Un `{}` vacío de JSON o un valor suelto se normalizan aquí. +function M.normalize(user) + user = user or {} + local out = {} + for k, v in pairs(M.default_config) do + out[k] = user[k] ~= nil and user[k] or vim.deepcopy(v) + end + for k, v in pairs(user) do + if out[k] == nil then + out[k] = v + end -- claves desconocidas se conservan + end + + for _, k in ipairs(ARRAY_FIELDS) do + if type(out[k]) ~= "table" then + out[k] = (out[k] == nil) and {} or { tostring(out[k]) } + else + local list = {} + for _, v in ipairs(out[k]) do + table.insert(list, v) + end + out[k] = list + end + end + return out +end + +function M.load() + local f = io.open(M.path, "r") + if not f then + return { version = 1, configs = {} } + end + local content = f:read("*a") + f:close() + + local ok, data = pcall(vim.json.decode, content) + if not ok or type(data) ~= "table" then + vim.notify("[hego] " .. M.path .. " no es JSON válido", vim.log.levels.ERROR) + return { version = 1, configs = {} } + end + data.version = data.version or 1 + data.configs = data.configs or {} + return data +end + +--- Pretty printer mínimo: el JSON se lee y se edita a mano. +local function pretty(value, indent) + indent = indent or "" + if type(value) ~= "table" then + return vim.json.encode(value) + end + + local inner, parts = indent .. " ", {} + if #value > 0 then + for _, v in ipairs(value) do + table.insert(parts, inner .. pretty(v, inner)) + end + if #parts == 0 then + return "[]" + end + return "[\n" .. table.concat(parts, ",\n") .. "\n" .. indent .. "]" + end + + for k, v in pairs(value) do + table.insert(parts, inner .. vim.json.encode(k) .. ": " .. pretty(v, inner)) + end + if #parts == 0 then + return "{}" + end + return "{\n" .. table.concat(parts, ",\n") .. "\n" .. indent .. "}" +end + +function M.save(data) + vim.fn.mkdir(vim.fn.fnamemodify(M.path, ":h"), "p") + local f = assert(io.open(M.path, "w")) + f:write(pretty(data) .. "\n") + f:close() +end + +--- Semilla para proyectos sin .hego/configs.json, desde el spec del plugin. +--- Los valores vienen de tus opts: board nrf54l15dk/nrf54l15/cpuapp, el +--- overlay boards/nrf54l15dk_nrf54l15_cpuapp.overlay y prj.conf. +function M.seed(opts) + return M.normalize({ + board = opts.board, + conf_files = opts.conf_file and { opts.conf_file } or {}, + overlays = opts.overlays or {}, + extra_cmake = opts.extra_cmake or {}, + build_dir = opts.build_dir or "build", + sysbuild = (opts.sysbuild == false) and "no" or "default", + }) +end + +return M diff --git a/lua/hego/detect.lua b/lua/hego/detect.lua index 6fe949c..852039b 100644 --- a/lua/hego/detect.lua +++ b/lua/hego/detect.lua @@ -16,7 +16,7 @@ function M.ncs_version(root) return out[#out] end ---- Toolchain más reciente: { dir, gcc }. +--- Toolchain más reciente: { dir, gcc, mtime }. function M.toolchain(root) local out = {} for _, d in ipairs(vim.fn.glob(root .. "/*", false, true)) do @@ -32,7 +32,7 @@ function M.toolchain(root) return out[1] end ---- Board: lo lee del CMakeCache si ya hay build; si no, nil. +--- Board desde el CMakeCache si ya existe build; si no, nil. function M.board(build_dir) local f = io.open(build_dir .. "/CMakeCache.txt", "r") if not f then diff --git a/lua/hego/exec.lua b/lua/hego/exec.lua index cad6f57..d03b8fb 100644 --- a/lua/hego/exec.lua +++ b/lua/hego/exec.lua @@ -11,43 +11,82 @@ function M.ncs(opts, cmd) return full end ---- Ejecuta async y vuelca la salida a un buffer scratch (no bloquea nvim). -function M.run_async(cmd, o) - o = o or {} - local buf = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_name(buf, o.title or "hego://run") - vim.cmd("botright split") - vim.api.nvim_win_set_buf(0, buf) - - local function append(data) - if not data or data == "" then - return +--- Lo único que NO pone `toolchain-manager launch` es ZEPHYR_BASE. +function M.zephyr_env(opts) + if opts.ncs_root and opts.ncs_version then + local zephyr = opts.ncs_root .. "/" .. opts.ncs_version .. "/zephyr" + if vim.fn.isdirectory(zephyr) == 1 then + return { ZEPHYR_BASE = zephyr } end - vim.api.nvim_buf_set_lines(buf, -1, -1, false, vim.split(data, "\n", { plain = true })) - vim.api.nvim_win_set_cursor(0, { vim.api.nvim_buf_line_count(buf), 0 }) + end + return {} +end + +--- Buffer de terminal reutilizable por nombre. +local function prepare_term(name) + local buf = vim.fn.bufnr(name) + + if buf ~= -1 then + -- Si hay un job vivo en ese terminal, lo paramos antes de reusarlo. + local job = vim.b[buf].terminal_job_id + if job then + pcall(vim.fn.jobstop, job) + vim.wait(200, function() + return vim.b[buf].terminal_job_id == nil + end) + end + else + buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_name(buf, name) + vim.bo[buf].bufhidden = "hide" end - return vim.system(cmd, { + vim.cmd("botright split") + vim.api.nvim_win_set_buf(0, buf) + -- dentro de prepare_term(name), justo antes del return + vim.keymap.set("t", "", "", { buffer = buf, silent = true }) + + vim.keymap.set("t", "", function() + local j = vim.b[buf].terminal_job_id + if j then + pcall(vim.fn.jobstop, j) + end + vim.cmd("stopinsert") + end, { buffer = buf, silent = true, desc = "hego: detener proceso" }) + return buf +end + +--- Ejecuta en un buffer de terminal (interactivo, ANSI, progreso). +--- Misma firma que la versión anterior: no hay que tocar las llamadas. +function M.run_async(cmd, o) + o = o or {} + local buf = prepare_term(o.title or "hego://run") + + -- Fusionamos con el entorno heredado: jobstart REEMPLAZA si le pasas env. + local env = vim.tbl_extend("force", vim.fn.environ(), o.env or {}) + + local job = vim.fn.jobstart(cmd, { + term = true, cwd = o.cwd, - text = true, - stdout = function(_, d) + env = env, + on_exit = function(_, code) vim.schedule(function() - append(d) + vim.b[buf].hego_exit = code + if o.on_exit then + o.on_exit({ code = code }) + end end) end, - stderr = function(_, d) - vim.schedule(function() - append(d) - end) - end, - }, function(obj) - vim.schedule(function() - append("\n[hego] exit: " .. tostring(obj.code)) - if o.on_exit then - o.on_exit(obj) - end - end) - end) + }) + + if job <= 0 then + vim.notify("[hego] no se pudo lanzar el comando", vim.log.levels.ERROR) + return + end + + -- Arrancamos en terminal-insert; Esc-Esc para salir (LazyVim ya lo mapea). + vim.cmd("startinsert") + return job end return M diff --git a/lua/hego/flash.lua b/lua/hego/flash.lua index 3deb106..cd6f330 100644 --- a/lua/hego/flash.lua +++ b/lua/hego/flash.lua @@ -1,41 +1,148 @@ local M = {} +--- nrfutil emite JSONL (un objeto por línea), no un array. +local function extract_devices(obj) + if type(obj) ~= "table" or type(obj.data) ~= "table" then + return nil + end + if obj.data.devices then + return obj.data.devices + end + if type(obj.data.data) == "table" and obj.data.data.devices then + return obj.data.data.devices + end + return nil +end + function M.devices() - local out = vim.fn.system({ "nrfutil", "device", "list", "--json" }) - local ok, data = pcall(vim.json.decode, out) - if not ok or type(data) ~= "table" then + local raw = vim.fn.system({ "nrfutil", "device", "list", "--json" }) + if vim.v.shell_error ~= 0 then return {} end + local devs = {} - for _, d in ipairs(data) do - if d.serial_number then - table.insert(devs, { - sn = d.serial_number, - name = (d.traits and d.traits.product) or "DK", - }) + for _, line in ipairs(vim.split(raw, "\n", { plain = true })) do + if line ~= "" then + local ok, obj = pcall(vim.json.decode, line) + if ok and obj then + local list = extract_devices(obj) + if list then + for _, d in ipairs(list) do + if d.serialNumber then + local name = (d.devkit and d.devkit.deviceFamily) or (d.usb and d.usb.product) or "DK" + table.insert(devs, { sn = d.serialNumber, name = name }) + end + end + if #devs > 0 then + break + end + end + end end end return devs end -function M.run(opts) +-- Modos soportados y el flag que añaden a `west flash`. +local MODES = { + flash = { flag = nil, title = "hego://flash" }, + erase = { flag = "--erase", title = "hego://flash-erase" }, + recover = { flag = "--recover", title = "hego://flash-recover" }, +} + +local CONFIRM = { + erase = "Se borra TODA la flash: particiones, factory data y estado de comisión.\n¿Seguir?", + recover = "Se borra toda la flash Y se desbloquea APPROTECT.\n" + .. "Es lo que hay que usar cuando el flash normal falla con " + .. "AP-Protect / readback protection.\n¿Seguir?", +} + +local function argv(opts, sn, mode) + local a = { "flash", "-d", opts.build_dir, "--dev-id", sn } + if MODES[mode].flag then + table.insert(a, MODES[mode].flag) + end + return a +end + +--- mode: "flash" (por defecto) | "erase" | "recover" +function M.run(opts, mode) + mode = mode or "flash" + + if not MODES[mode] then + vim.notify("[hego] modo de flash desconocido: " .. tostring(mode), vim.log.levels.ERROR) + return + end + + if CONFIRM[mode] then + if vim.fn.confirm(CONFIRM[mode], "&Sí\n&No", 2) ~= 1 then + return + end + end + local devs = M.devices() if #devs == 0 then vim.notify("[hego] no hay ninguna placa conectada", vim.log.levels.WARN) return end + local exec = require("hego.exec") + local function go(sn) - local exec = require("hego.exec") - local cmd = exec.ncs(opts, { "west", "flash", "-d", opts.build_dir, "--dev-id", sn }) - exec.run_async(cmd, { title = "hego://flash" }) + exec.run_async(exec.ncs(opts, argv(opts, sn, mode)), { + title = MODES[mode].title, + cwd = vim.fn.getcwd(), + env = exec.zephyr_env(opts), + }) end if #devs == 1 then return go(devs[1].sn) end + vim.ui.select(devs, { - prompt = "¿A qué placa flasheo?", + prompt = "¿A qué placa?", + format_item = function(d) + return d.name .. " (" .. d.sn .. ")" + end, + }, function(c) + if c then + go(c.sn) + end + end) +end + +--- Plan B: recuperar la placa sin pasar por west ni por sysbuild. +--- Útil si `west flash --recover` se atraganta con el multi-dominio. +function M.device_recover(opts) + local devs = M.devices() + if #devs == 0 then + vim.notify("[hego] no hay ninguna placa conectada", vim.log.levels.WARN) + return + end + + if + vim.fn.confirm("Se borra toda la flash de la placa y se desbloquea APPROTECT.\n¿Seguir?", "&Sí\n&No", 2) ~= 1 + then + return + end + + local exec = require("hego.exec") + + local function go(sn) + -- Ojo: esto NO va envuelto en el toolchain, es nrfutil a pelo. + exec.run_async({ "nrfutil", "device", "recover", "--serial-number", sn }, { + title = "hego://device-recover", + cwd = vim.fn.getcwd(), + }) + end + + if #devs == 1 then + return go(devs[1].sn) + end + + vim.ui.select(devs, { + prompt = "¿Qué placa recupero?", format_item = function(d) return d.name .. " (" .. d.sn .. ")" end, diff --git a/lua/hego/init.lua b/lua/hego/init.lua index e2de3ab..4dbbbb5 100644 --- a/lua/hego/init.lua +++ b/lua/hego/init.lua @@ -3,15 +3,27 @@ local M = {} M.defaults = { ncs_root = vim.fn.expand("~/ncs"), toolchains_root = vim.fn.expand("~/ncs/toolchains"), - ncs_version = nil, -- nil = autodetectar (p.ej. "v3.4.0") - toolchain_dir = nil, -- nil = autodetectar - board = nil, -- nil = leer de build/CMakeCache.txt + ncs_version = nil, + toolchain_dir = nil, + board = nil, build_dir = "build", conf_file = "prj.conf", sysbuild = true, - overlays = {}, -- { "boards/nrf54l15dk_nrf54l15_cpuapp.overlay" } - extra_cmake = {}, -- { "-DCONFIG_DEBUG_THREAD_INFO=y" } - keys = { build = "nb", pristine = "np", flash = "nf" }, + overlays = {}, + extra_cmake = {}, + keys = { + build = "nb", + pristine = "np", + flash = "nf", + flash_erase = "nE", + flash_recover = "nR", + device_recover = "nD", + kconfig = "nk", + memory = "nm", + config = "nc", + build_config = "nB", + monitor = "nt", + }, } M.options = {} @@ -37,12 +49,67 @@ function M.setup(opts) return o end --- API que consumen keymaps y comandos de usuario function M.build(pristine) return require("hego.west").build(M.options, pristine) end -function M.flash() - return require("hego.flash").run(M.options) + +--- mode: nil/"flash" | "erase" | "recover" +function M.flash(mode) + return require("hego.flash").run(M.options, mode) +end + +function M.device_recover() + return require("hego.flash").device_recover(M.options) +end + +function M.kconfig() + return require("hego.targets").run(M.options, "menuconfig", "hego://menuconfig") +end + +function M.memory_report() + return require("hego.targets").memory(M.options) +end + +function M.monitor() + return require("hego.monitor").run(M.options) +end + +function M.edit_config() + local Config = require("hego.config") + + if vim.fn.filereadable(Config.path) == 0 then + Config.save({ + version = 1, + configs = { default = Config.seed(M.options) }, + }) + vim.notify("[hego] creado " .. Config.path .. " (sembrado desde tus opts)", vim.log.levels.INFO) + end + + vim.cmd.edit(vim.fn.fnamemodify(Config.path, ":p")) +end + +function M.build_from_config(pristine) + local Config = require("hego.config") + local data = Config.load() + local names = vim.tbl_keys(data.configs) + + if #names == 0 then + vim.notify("[hego] no hay configs en " .. Config.path .. " (usa nc)", vim.log.levels.WARN) + return + end + table.sort(names) + + vim.ui.select(names, { + prompt = "Construir con configuración", + format_item = function(n) + return n + end, + }, function(choice) + if not choice then + return + end + require("hego.west").build(M.options, pristine, Config.normalize(data.configs[choice])) + end) end return M diff --git a/lua/hego/keymaps.lua b/lua/hego/keymaps.lua index 5ec8c9c..5cb456d 100644 --- a/lua/hego/keymaps.lua +++ b/lua/hego/keymaps.lua @@ -13,6 +13,30 @@ function M.setup(opts) vim.keymap.set("n", k.flash, function() H.flash() end, { desc = "NCS: Flash" }) + vim.keymap.set("n", k.flash_erase, function() + H.flash("erase") + end, { desc = "NCS: Flash (--erase)" }) + vim.keymap.set("n", k.flash_recover, function() + H.flash("recover") + end, { desc = "NCS: Flash (--recover)" }) + vim.keymap.set("n", k.device_recover, function() + H.device_recover() + end, { desc = "NCS: Device recover (nrfutil)" }) + vim.keymap.set("n", k.kconfig, function() + H.kconfig() + end, { desc = "NCS: Kconfig (menuconfig)" }) + vim.keymap.set("n", k.memory, function() + H.memory_report() + end, { desc = "NCS: Memory report" }) + vim.keymap.set("n", k.config, function() + H.edit_config() + end, { desc = "NCS: Edit build configs" }) + vim.keymap.set("n", k.build_config, function() + H.build_from_config() + end, { desc = "NCS: Build with config..." }) + vim.keymap.set("n", k.monitor, function() + H.monitor() + end, { desc = "NCS: Monitor serie" }) end return M diff --git a/lua/hego/lsp.lua b/lua/hego/lsp.lua index 09fb608..ef9248b 100644 --- a/lua/hego/lsp.lua +++ b/lua/hego/lsp.lua @@ -1,11 +1,34 @@ local M = {} -local SKIP = { mcuboot = true, matter_factory_data = true } +local SKIP = { + mcuboot = true, + matter_factory_data = true, +} + +--- Reinicia clangd para que relea compile_commands.json. +--- :LspRestart lo aporta nvim-lspconfig; puede no existir según la versión. +local function restart_lsp() + if vim.fn.exists(":LspRestart") == 2 then + vim.cmd("LspRestart") + return + end + + -- Fallback: Neovim 0.11+ sabe (des)habilitar servidores por nombre. + local ok = pcall(function() + vim.lsp.enable("clangd", false) + vim.defer_fn(function() + vim.lsp.enable("clangd", true) + end, 150) + end) + if not ok then + vim.notify("[hego] no tengo :LspRestart; reinicia clangd a mano", vim.log.levels.WARN) + end +end function M.link(opts) local m = vim.fn.glob(opts.build_dir .. "/*/compile_commands.json", false, true) if #m == 0 then - m = vim.fn.glob(opts.build_dir .. "/compile_commands.json", false, true) -- sin sysbuild + m = vim.fn.glob(opts.build_dir .. "/compile_commands.json", false, true) end if #m == 0 then vim.notify("[hego] no encuentro compile_commands.json", vim.log.levels.WARN) @@ -32,7 +55,8 @@ function M.link(opts) vim.notify("[hego] fallo creando el symlink", vim.log.levels.ERROR) return end - vim.cmd("LspRestart") -- clangd solo lo lee al arrancar + + restart_lsp() vim.notify("[hego] compile_commands.json -> " .. chosen, vim.log.levels.INFO) end diff --git a/lua/hego/monitor.lua b/lua/hego/monitor.lua new file mode 100644 index 0000000..cb62fdb --- /dev/null +++ b/lua/hego/monitor.lua @@ -0,0 +1,40 @@ +local M = {} + +local function candidates(opts) + if opts.monitor_port then + return { opts.monitor_port } + end + return vim.fn.glob("/dev/ttyACM*", false, true) +end + +function M.run(opts) + local ports = candidates(opts) + if #ports == 0 then + vim.notify("[hego] ningún /dev/ttyACM*; ¿DK conectado?", vim.log.levels.WARN) + return + end + + local exec = require("hego.exec") + + local function go(port) + -- tio reconecta solo si el puerto re-enumera (p. ej. tras un flash). + exec.run_async({ "tio", port }, { + title = "hego://monitor", + cwd = vim.fn.getcwd(), + }) + end + + if #ports == 1 then + return go(ports[1]) + end + + vim.ui.select(ports, { + prompt = "Monitor serie", + }, function(c) + if c then + go(c) + end + end) +end + +return M diff --git a/lua/hego/west.lua b/lua/hego/west.lua index 7e6b12c..c5dcda9 100644 --- a/lua/hego/west.lua +++ b/lua/hego/west.lua @@ -1,32 +1,90 @@ local M = {} -function M.build(opts, pristine) - local a = { "build", "-d", opts.build_dir, vim.fn.getcwd(), "--board", opts.board } - if opts.sysbuild then - table.insert(a, "--sysbuild") +--- Config del formulario -> argumentos de `west build`. +local function config_args(cfg) + local a = {} + if cfg.board then + vim.list_extend(a, { "--board", cfg.board }) end + + if cfg.sysbuild == "yes" then + table.insert(a, "--sysbuild") + elseif cfg.sysbuild == "no" then + table.insert(a, "--no-sysbuild") -- verificar nombre exacto en tu west + end + + table.insert(a, "--") + table.insert(a, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON") + + local function multi(flag, list) + if list and #list > 0 then + table.insert(a, flag .. "=" .. table.concat(list, ";")) + end + end + multi("-DCONF_FILE", cfg.conf_files) + multi("-DEXTRA_CONF_FILE", cfg.extra_conf_files) + multi("-DDTC_OVERLAY_FILE", cfg.overlays) + multi("-DEXTRA_DTC_OVERLAY_FILE", cfg.extra_overlays) + multi("-DSNIPPET", cfg.snippets) + + if cfg.optimization == "size" then + table.insert(a, "-DCONFIG_SIZE_OPTIMIZATIONS=y") + elseif cfg.optimization == "speed" then + table.insert(a, "-DCONFIG_SPEED_OPTIMIZATIONS=y") + elseif cfg.optimization == "debug" then + table.insert(a, "-DCONFIG_DEBUG_OPTIMIZATIONS=y") + end + + if cfg.debug_thread_info then + table.insert(a, "-DCONFIG_DEBUG_THREAD_INFO=y") + end + + for _, e in ipairs(cfg.extra_cmake or {}) do + table.insert(a, e) + end + return a +end + +--- Config del spec del plugin (one-liner) -> config del formulario. +local function from_opts(opts) + return { + board = opts.board, + conf_files = opts.conf_file and { opts.conf_file } or {}, + overlays = opts.overlays or {}, + extra_cmake = opts.extra_cmake or {}, + build_dir = opts.build_dir or "build", + sysbuild = (opts.sysbuild == false) and "no" or "default", + } +end + +function M.build(opts, pristine, cfg) + cfg = cfg or from_opts(opts) + + if cfg.generate_only then + vim.notify("[hego] 'Generate only' todavía no está cableado (pendiente de verificar)", vim.log.levels.WARN) + end + + local a = { + "build", + "-d", + cfg.build_dir or opts.build_dir, + vim.fn.getcwd(), + } if pristine then table.insert(a, "--pristine") end - table.insert(a, "--") - table.insert(a, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON") - if opts.conf_file then - table.insert(a, "-DCONF_FILE=" .. opts.conf_file) - end - if #opts.overlays > 0 then - table.insert(a, "-DDTC_OVERLAY_FILE=" .. table.concat(opts.overlays, ";")) - end - for _, e in ipairs(opts.extra_cmake or {}) do - table.insert(a, e) - end + vim.list_extend(a, config_args(cfg)) local exec = require("hego.exec") local cmd = exec.ncs(opts, vim.list_extend({ "west" }, a)) + return exec.run_async(cmd, { title = "hego://build", + cwd = vim.fn.getcwd(), + env = exec.zephyr_env(opts), on_exit = function(obj) if obj.code == 0 then - require("hego.lsp").link(opts) + require("hego.lsp").link(cfg) end end, }) diff --git a/schemas/hego-configs.json b/schemas/hego-configs.json new file mode 100644 index 0000000..bdca773 --- /dev/null +++ b/schemas/hego-configs.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "hego.nvim build configurations", + "type": "object", + "required": ["version", "configs"], + "properties": { + "version": { "type": "integer", "const": 1 }, + "configs": { + "type": "object", + "additionalProperties": { "$ref": "#/definitions/config" } + } + }, + "definitions": { + "stringList": { "type": "array", "items": { "type": "string" } }, + "config": { + "type": "object", + "properties": { + "board": { "type": ["string", "null"] }, + "conf_files": { "$ref": "#/definitions/stringList" }, + "extra_conf_files": { "$ref": "#/definitions/stringList" }, + "overlays": { "$ref": "#/definitions/stringList" }, + "extra_overlays": { "$ref": "#/definitions/stringList" }, + "snippets": { "$ref": "#/definitions/stringList" }, + "optimization": { "enum": ["default", "size", "speed", "debug"] }, + "debug_thread_info": { "type": "boolean" }, + "extra_cmake": { "$ref": "#/definitions/stringList" }, + "build_dir": { "type": "string" }, + "generate_only": { "type": "boolean" }, + "sysbuild": { "enum": ["default", "yes", "no"] } + } + } + } +}