diff --git a/dotfiles/nvim/lua/plugins/lsp/c.lua b/dotfiles/nvim/lua/plugins/lsp/c.lua index d7e8bed..c0a7c09 100644 --- a/dotfiles/nvim/lua/plugins/lsp/c.lua +++ b/dotfiles/nvim/lua/plugins/lsp/c.lua @@ -1,5 +1,8 @@ return function () - require"lspconfig".clangd.setup { - capabilities = require"cmp_nvim_lsp".default_capabilities() + require"lspconfig".ccls.setup { + capabilities = require"cmp_nvim_lsp".default_capabilities(), + filetypes = { + "c" + } } end diff --git a/dotfiles/nvim/lua/plugins/lsp/cxx.lua b/dotfiles/nvim/lua/plugins/lsp/cxx.lua new file mode 100644 index 0000000..3560eb4 --- /dev/null +++ b/dotfiles/nvim/lua/plugins/lsp/cxx.lua @@ -0,0 +1,8 @@ +return function () + require"lspconfig".clangd.setup { + capabilities = require"cmp_nvim_lsp".default_capabilities(), + filetypes = { + "cpp", "objc", "objcpp", "cuda", "proto" + } + } +end diff --git a/dotfiles/nvim/lua/settings/autocmds.lua b/dotfiles/nvim/lua/settings/autocmds.lua index e69de29..471a38c 100644 --- a/dotfiles/nvim/lua/settings/autocmds.lua +++ b/dotfiles/nvim/lua/settings/autocmds.lua @@ -0,0 +1,37 @@ +vim.api.nvim_create_autocmd("BufReadPost", { + pattern = "*.h", + callback = function() + -- Toggle .h files between being interpreted as C and C++ + -- in case I have to work on a C++ header that was saved + -- (incorrectly) as a C header file. + vim.api.nvim_create_user_command("Fytwmmrt", function() + if not vim.b.fu then + vim.b.fu = true + vim.bo.filetype = "cpp" + vim.cmd([[ + LspStop ccls + LspStart clangd + ]]) + else + vim.b.fu = false + vim.bo.filetype = "c" + vim.cmd([[ + LspStop ccls + LspStart clangd + ]]) + end + end, { desc = "Fuck you to whoever made me run this."}) + + -- Set all .h files to be interpreted as C by default instead + -- of C++. If you use .h for your C++ headers instead of .hpp + -- you should be ashamed of yourself and change and grow as a + -- person as to not repeat such heretical offenses. + if not vim.b.fu then + vim.bo.filetype = "c" + vim.cmd([[ + LspStop clangd + LspStart ccls + ]]) + end + end, +}) diff --git a/modules/packages/nvim.nix b/modules/packages/nvim.nix index 8ec4338..cc2faa8 100644 --- a/modules/packages/nvim.nix +++ b/modules/packages/nvim.nix @@ -21,6 +21,7 @@ (llvmPackages_19.clang-tools.override { enableLibcxx = true; }) + ccls ripgrep nil gcc14