Files
hego.nvim/lua/hego/lsp.lua
T

64 lines
1.5 KiB
Lua

local M = {}
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)
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
restart_lsp()
vim.notify("[hego] compile_commands.json -> " .. chosen, vim.log.levels.INFO)
end
return M