add some bugs

This commit is contained in:
dlond 2025-05-27 03:50:02 +12:00
parent 0a859f314e
commit 2113b33a58
4 changed files with 62 additions and 9 deletions

View file

@ -66,4 +66,60 @@ end
return {
pick_executable = pick_executable,
clangd_base_cmd = {
'clangd',
'--background-index',
'--clang-tidy',
'--header-insertion=never',
'--query-driver=' .. vim.fn.trim(vim.fn.system 'which clang++'),
'--resource-dir=' .. vim.fn.trim(vim.fn.system 'clang++ --print-resource-dir'),
},
make_clangd_cmd = function(self, compile_commands_dir)
local cmd = vim.deepcopy(self.clangd_base_cmd)
table.insert(cmd, '--compile-commands-dir=' .. compile_commands_dir)
return cmd
end,
find_targets = function()
return vim.fn.systemlist 'fd -u compile_commands.json -x dirname {}'
end,
get_target = function(self)
return vim.g.current_target_dir or 'build/debug'
end,
set_target = function(self, dir)
vim.g.current_target_dir = dir
self:reload_clangd()
end,
pick_target = function(self)
local targets = self.find_targets()
if vim.tbl_isempty(targets) then
vim.notify('No build targets found.', vim.log.WARN)
return
end
vim.ui.select(targets, { prompt = 'Select build target:' }, function(choice)
if choice then
self:set_target(choice)
end
end)
end,
reload_clangd = function(self)
local lspconfig = require 'lspconfig'
local clients = vim.lsp.get_active_clients { name = 'clangd' }
for _, cliet in ipairs(clients) do
client.stop()
end
vim.defer_fn(function()
lspconfig.clangd.setup {
cmd = self:make_clangd_cmd(self:get_target()),
}
vim.cmd 'edit'
end, 200)
end,
}