-- C language pack: plugins that only load for C/C++ -- - clangd (LSP) via nvim-lspconfig -- - clang-format on save via conform.nvim return { -- LSP framework (just the client; the *server* is clangd you installed with Homebrew) { "neovim/nvim-lspconfig", ft = { "c", "cpp" }, -- load only when editing C/C++ config = function() local lsp = require("lspconfig") -- Minimal, sensible clangd setup. -- Tip: clangd finds your project root via compile_commands.json, compile_flags.txt, or .git lsp.clangd.setup({ -- You can pass extra flags here later (e.g., to enable clang-tidy) -- cmd = { "clangd", "--header-insertion=never" }, -- capabilities = ... (we'll keep defaults until you add completion later) }) -- That's it. Keymaps are added in c/keybindings.lua on LspAttach. end, }, -- Formatting with clang-format (runs on save for C/C++) -- If you later move Conform to core, keep this block here: it will just *extend* its opts. { "stevearc/conform.nvim", ft = { "c", "cpp" }, opts = function(_, opts) opts.formatters_by_ft = opts.formatters_by_ft or {} opts.formatters_by_ft.c = { "clang-format" } opts.formatters_by_ft.cpp = { "clang-format" } return opts end, config = function(_, opts) local conform = require("conform") conform.setup(opts) -- Format C/C++ buffers on save. If clang-format isn't found, -- Conform will fall back to LSP formatting (safe). vim.api.nvim_create_autocmd("BufWritePre", { pattern = { "*.c", "*.h", "*.cpp", "*.hpp" }, callback = function(args) conform.format({ bufnr = args.buf, lsp_fallback = true }) end, }) end, }, { "neovim/nvim-lspconfig", ft = { "c", "cpp" }, config = function() local lsp = require("lspconfig") -- Advertise cmp’s capabilities to clangd (safe even if cmp isn’t loaded yet) local capabilities = vim.lsp.protocol.make_client_capabilities() local ok, cmp_lsp = pcall(require, "cmp_nvim_lsp") if ok then capabilities = cmp_lsp.default_capabilities(capabilities) end lsp.clangd.setup({ capabilities = capabilities, cmd = { "clangd", "--background-index", "--pch-storage=memory"}, -- (keep any flags you had here) }) end, }, }