Files
dotfiles/nvim/lua/nvim-cmp.lua
T
2025-12-23 19:52:44 +01:00

83 lines
2.5 KiB
Lua

-- Set up nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
-- vim.fn["UltiSnips#ExpandSnippet"]()
vim.fn["UltiSnips#Anon"](args.body) -- previous one mostly works
end,
},
mapping = cmp.mapping.preset.insert({
['<C-k>'] = cmp.mapping.select_prev_item(),
['<C-j>'] = cmp.mapping.select_next_item(),
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<tab>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'ultisnips' },
}, {
{ 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 }
})
-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local lsp = require('lspconfig')
-- lsp.ccls.setup{
-- capabilities = capabilities,
-- init_options = {
-- cache = {
-- directory = vim.fn.expand("~/.cache/ccls") -- Store index globally
-- },
-- compilationDatabaseDirectory = "build", -- Uses 'build/compile_commands.json' if present
-- highlight = { lsRanges = true }, -- Improves semantic highlighting
-- index = {
-- threads = 4, -- Adjust based on your CPU (more threads = faster indexing)
-- initialBlacklist = { ".*_test.cpp", ".*_unittest.cpp" }
-- -- initialBlacklist = { ".*_test.cpp", ".*_unittest.cpp", "/home/furtest/linux_bidouille/.*" } -- Avoid indexing test files
-- },
-- completion = {
-- detailedLabel = true -- Better completion info
-- },
-- diagnostics = {
-- onChange = 300 -- Delay diagnostics updates for better performance
-- }
-- }
-- }
-- clangd and ccls are both C and C++ language servers
-- having them both active at the same time is useless
lsp.clangd.setup {
capabilities = capabilities,
cmd = { "clangd", "--enable-config" },
}