local M = {} local SKIP = { mcuboot = true, matter_factory_data = true } 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 end if #m == 0 then vim.notify("[hego] no encuentro compile_commands.json", vim.log.levels.WARN) return end local chosen for _, p in ipairs(m) do local image = vim.fn.fnamemodify(vim.fn.fnamemodify(p, ":h"), ":t") if not SKIP[image] then chosen = p break end end chosen = chosen or m[1] vim.fn.system({ "ln", "-sfn", vim.fn.fnamemodify(chosen, ":p"), vim.fn.getcwd() .. "/compile_commands.json", }) if vim.v.shell_error ~= 0 then vim.notify("[hego] fallo creando el symlink", vim.log.levels.ERROR) return end vim.cmd("LspRestart") -- clangd solo lo lee al arrancar vim.notify("[hego] compile_commands.json -> " .. chosen, vim.log.levels.INFO) end return M