Files
hego.nvim/lua/hego/detect.lua
T
unai a4a5bfe636 feat: núcleo del plugin NCS (build, flash, LSP)
Primera versión funcional del plugin para nRF Connect SDK en LazyVim.

Incluye:
- setup() con opciones por proyecto y API pública (build, flash)
- detect: resolución en runtime de versión NCS, toolchain y board
  (sin hashes hardcodeados)
- exec: wrapper async sobre vim.system + entorno NCS
- west: construcción del comando build (--sysbuild, -DCONF_FILE,
  -DDTC_OVERLAY_FILE, -DCMAKE_EXPORT_COMPILE_COMMANDS=ON)
- lsp: symlink de compile_commands.json desde build/<image>/ y
  LspRestart (clangd solo lo lee al arrancar)
- flash: detección de placas vía nrfutil device list + selector
- keymaps: <leader>nb (build), <leader>np (pristine), <leader>nf (flash)
2026-10-10 18:36:16 +02:00

53 lines
1.1 KiB
Lua

local M = {}
local function stat(p)
return vim.uv.fs_stat(p)
end
--- Versión NCS más reciente instalada (p.ej. "v3.4.0").
function M.ncs_version(root)
local out = {}
for _, d in ipairs(vim.fn.glob(root .. "/v*", false, true)) do
if stat(d .. "/zephyr") then
table.insert(out, vim.fn.fnamemodify(d, ":t"))
end
end
table.sort(out)
return out[#out]
end
--- Toolchain más reciente: { dir, gcc }.
function M.toolchain(root)
local out = {}
for _, d in ipairs(vim.fn.glob(root .. "/*", false, true)) do
local gcc = d .. "/opt/zephyr-sdk/gnu/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc"
local st = stat(gcc)
if st then
table.insert(out, { dir = d, gcc = gcc, mtime = st.mtime.sec })
end
end
table.sort(out, function(a, b)
return a.mtime > b.mtime
end)
return out[1]
end
--- Board: lo lee del CMakeCache si ya hay build; si no, nil.
function M.board(build_dir)
local f = io.open(build_dir .. "/CMakeCache.txt", "r")
if not f then
return nil
end
for line in f:lines() do
local b = line:match("^BOARD:STRING=(.+)$")
if b then
f:close()
return b
end
end
f:close()
return nil
end
return M