diff --git a/nvim/lua/language_servers/clangd.lua b/nvim/lua/language_servers/clangd.lua index 25169ca..29621c4 100644 --- a/nvim/lua/language_servers/clangd.lua +++ b/nvim/lua/language_servers/clangd.lua @@ -22,6 +22,16 @@ local function switch_between_header_and_source(bufnr) end local M = { + cmd = { + "clangd", + "--background-index", + "--clang-tidy", + "--completion-style=bundled", + -- "--cross-file-rename", // This has been deprecated + "--rename-file-limit=0", + "--header-insertion=iwyu", + "--inlay-hints", + }, commands = { ClangdSwitchSourceHeader = { function() diff --git a/nvim/lua/plugs/cmp.lua b/nvim/lua/plugs/cmp.lua new file mode 100644 index 0000000..ad4f272 --- /dev/null +++ b/nvim/lua/plugs/cmp.lua @@ -0,0 +1,67 @@ +return { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + }, + config = function() + -- Set up nvim-cmp. + local cmp = require("cmp") + + cmp.setup({ + snippet = { + expand = function(args) + vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) + end, + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + }, + { + { name = "buffer" }, + }) + }) + + -- Set configuration for specific filetype. + cmp.setup.filetype("gitcommit", { + sources = cmp.config.sources({ + { name = "git" }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). + }, { + { name = "buffer" }, + }) + }) + + -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline({ "/", "?" }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" } + } + }) + + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" } + }, { + { name = "cmdline" } + }), + matching = { disallow_symbol_nonprefix_matching = false } + }) + + end, +} diff --git a/nvim/lua/plugs/mason_lsp.lua b/nvim/lua/plugs/mason_lsp.lua index 97817d2..6975af8 100644 --- a/nvim/lua/plugs/mason_lsp.lua +++ b/nvim/lua/plugs/mason_lsp.lua @@ -20,6 +20,8 @@ return { end, lua_files) -- Create a new table which contains the non-lsp setups for Mason (linters, formatters, etc) + -- IMPORTANT: Make sure to leave rust-analyzer out of this list, as it can cause conflicts with rustaceanvim. + -- Install rust-analyzer using your systems package manager instead. local mason_installs = vim.list_extend({ "clang-format", "cmakelang", @@ -34,11 +36,27 @@ return { require("mason-update-all").setup() -- Iterate each server and setup + local capabilities = require("cmp_nvim_lsp").default_capabilities() local lspconfig = require("lspconfig") for _, server_name in ipairs(server_names) do local server = lspconfig[server_name] if server then local server_table = require("language_servers/" .. server_name) + server_table.capabilities = capabilities + server_table.on_attach = function(client, bufnr) + vim.lsp.inlay_hint.enable(bufnr, true) + + if client.server_capabilities.documentFormattingProvider then + vim.api.nvim_buf_create_user_command(bufnr, "Format", vim.lsp.buf.format, { nargs = 0 }) + vim.api.nvim_create_autocmd("BufWritePre", { + buffer = bufnr, + callback = function() + vim.lsp.buf.format() + end, + }) + end + end + server.setup(server_table) -- Run the post_setup function if it exists