From ad30ff195f466d2dd63f8ed791da7bbb4f1e1f52 Mon Sep 17 00:00:00 2001 From: caiowakamatsu Date: Thu, 25 Jun 2026 19:44:31 -0300 Subject: [PATCH] turn off LSP for C++ --- nvim/lua/config/lsp.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/nvim/lua/config/lsp.lua b/nvim/lua/config/lsp.lua index e792cb8..8027f76 100644 --- a/nvim/lua/config/lsp.lua +++ b/nvim/lua/config/lsp.lua @@ -31,14 +31,6 @@ vim.filetype.add({ cuh = "cuda", }, }) --- clangd -vim.lsp.config("clangd", { - cmd = { "clangd", "--compile-commands-dir=build", "--experimental-modules-support" }, - capabilities = caps, - on_attach = on_attach, - filetypes = { "c", "cpp", "cc", "cxx", "c++", "ixx", "cu", "cuh", "cuda" }, -}) -vim.lsp.enable("clangd") -- rust-analyzer vim.lsp.config("rust_analyzer", { @@ -86,9 +78,19 @@ vim.api.nvim_create_autocmd("BufWritePre", { group = vim.api.nvim_create_augroup("AutoFormatOnSave", { clear = true }), pattern = "*", callback = function() + local ext = vim.fn.expand("%:e") + local cpp_exts = { cpp = true, cxx = true, hpp = true, ixx = true } + + if cpp_exts[ext] then + local filepath = vim.fn.expand("%:p") + vim.fn.system({ "clang-format", "-i", filepath }) + vim.cmd("edit!") -- reload the buffer after in-place formatting + return + end + for _, client in pairs(vim.lsp.get_active_clients({ bufnr = 0 })) do if client.supports_method("textDocument/formatting") then - vim.lsp.buf.format({ async = true, timeout_ms=5000 }) + vim.lsp.buf.format({ async = false, timeout_ms = 5000 }) return end end