80 lines
2.2 KiB
Lua
80 lines
2.2 KiB
Lua
-- Set up nvim-cmp.
|
|
local cmp = require'cmp'
|
|
|
|
cmp.setup({
|
|
snippet = {
|
|
expand = function(args)
|
|
vim.fn["UltiSnips#Anon"](args.body)
|
|
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" } -- 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,
|
|
-- }
|
|
|