From 381206c8f21e6db207eb6d383cc3324d1dbfb415 Mon Sep 17 00:00:00 2001 From: dlond Date: Fri, 30 May 2025 04:33:51 +1200 Subject: [PATCH] try watch compile_config --- lua/custom/plugins/lsp/clangd.lua | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lua/custom/plugins/lsp/clangd.lua b/lua/custom/plugins/lsp/clangd.lua index a9bed36d..16a78ed4 100644 --- a/lua/custom/plugins/lsp/clangd.lua +++ b/lua/custom/plugins/lsp/clangd.lua @@ -124,12 +124,22 @@ return { 'neovim/nvim-lspconfig', ft = M.clang_filetypes, config = function() - local dir = find_compile_commands() - M.start_clangd(dir) - if dir ~= '' then - M.watch_compile_commands(dir) - end + vim.api.nvim_create_autocmd('BufReadPost', { + group = vim.api.nvim_create_augroup('clangd-lazy-init', { clear = true }), + pattern = '*', + callback = function(args) + local ft = vim.bo[args.buf].filetype + if vim.tbl_contains(M.clang_filetypes, ft) then + local dir = find_compile_commands() + M.start_clangd(dir) + if dir ~= '' then + M.watch_compile_commands(dir) + end - vim.keymap.set('n', 'cc', M.pick_commands_dir, { desc = 'Pick location of compile_commands.json for clangd' }) + vim.keymap.set('n', 'cc', M.pick_commands_dir, { desc = 'Pick location of compile_commands.json for clangd' }) + vim.api.nvim_clear_autocmds { group = 'clangd-lazy-init' } + end + end, + }) end, }