aboutsummaryrefslogtreecommitdiff
path: root/lua/config_cmp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/config_cmp.lua')
-rw-r--r--lua/config_cmp.lua188
1 files changed, 188 insertions, 0 deletions
diff --git a/lua/config_cmp.lua b/lua/config_cmp.lua
new file mode 100644
index 0000000..4f0feb8
--- /dev/null
+++ b/lua/config_cmp.lua
@@ -0,0 +1,188 @@
+vim.opt.completeopt = "menu,menuone,noselect"
+local constants = require("constants")
+
+-- Setup lspconfig.
+require'lspconfig'.clangd.setup{}
+require'lspconfig'.pylsp.setup{}
+
+local cmp = require'cmp'
+
+local kind_icons = {
+ Text = "",
+ Method = "",
+ Function = "󰊕",
+ Constructor = "",
+ Field = "",
+ Variable = "󰫧",
+ Class = "",
+ Interface = "",
+ Module = "",
+ Property = "",
+ Unit = "",
+ Value = "",
+ Enum = "",
+ Keyword = "",
+ Snippet = "",
+ Color = "",
+ File = "",
+ Reference = "",
+ Folder = "",
+ EnumMember = "",
+ Constant = "",
+ Struct = "",
+ Event = "",
+ Operator = "",
+ TypeParameter = "",
+}
+
+-- The key mapping for the cmd.
+local cmd_mapping = {
+ ['<Tab>'] = {
+ c = function()
+ if cmp.visible() then
+ cmp.select_next_item()
+ else
+ feedkeys.call(keymap.t('<C-z>'), 'n')
+ end
+ end
+ },
+
+ ['<S-Tab>'] = {
+ c = function()
+ if cmp.visible() then
+ cmp.select_prev_item()
+ else
+ feedkeys.call(keymap.t('<C-z>'), 'n')
+ end
+ end
+ },
+
+ [constants.next_key] = {
+ c = function(fallback)
+ if cmp.visible() then
+ cmp.select_next_item()
+ else
+ fallback()
+ end
+ end
+ },
+
+ [constants.previous_key] = {
+ c = function(fallback)
+ if cmp.visible() then
+ cmp.select_prev_item()
+ else
+ fallback()
+ end
+ end
+ },
+
+ [constants.close_key] = {
+ c = cmp.mapping.close(),
+ }
+}
+
+-- Setup time!!!!
+cmp.setup({
+ snippet = {
+ -- REQUIRED - you must specify a snippet engine
+ expand = function(args)
+ require('luasnip').lsp_expand(args.body) -- For `luasnip` usersc;
+ end,
+ },
+ window = {
+ completion = cmp.config.window.bordered(),
+ documentation = cmp.config.window.bordered(),
+ },
+ mapping = {
+ [constants.next_key] = cmp.mapping.select_next_item(),
+ [constants.previous_key] = cmp.mapping.select_prev_item(),
+ ["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
+ ["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
+ ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
+ ["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
+ [constants.close_key] = cmp.mapping {
+ i = cmp.mapping.abort(),
+ c = cmp.mapping.close(),
+ },
+ -- Accept currently selected item. If none selected, `select` first item.
+ -- Set `select` to `false` to only confirm explicitly selected items.
+ ["<CR>"] = cmp.mapping.confirm { select = true },
+ },
+ formatting = {
+ fields = { "kind", "abbr", "menu" },
+ format = function(entry, vim_item)
+ -- Kind icons
+ vim_item.kind = string.format("%s", kind_icons[vim_item.kind])
+ -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind
+ vim_item.menu = ({
+ nvim_lsp = "[LSP]",
+ luasnip = "[Snippet]",
+ buffer = "[Buffer]",
+ path = "[Path]",
+ nvim_lua = "[nvim_lua]",
+ })[entry.source.name]
+ return vim_item
+ end,
+ },
+ sources = {
+ { name = 'nvim_lsp' },
+ { name = 'nvim_lua' },
+ { name = 'luasnip' }, -- For luasnip users.
+ { name = 'path' },
+ { name = 'buffer' },
+
+ },
+})
+
+-- Set configuration for specific filetype.
+cmp.setup.filetype('gitcommit', {
+ sources = cmp.config.sources({
+ { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
+ }, {
+ { name = 'buffer' },
+ })
+})
+
+-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
+cmp.setup.cmdline('/', {
+ mapping = cmd_mapping,
+ sources = {
+ { name = 'buffer' }
+ }
+})
+
+-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
+cmp.setup.cmdline(':', {
+ mapping = cmd_mapping,
+ sources = cmp.config.sources({
+ { name = 'path' }
+ }, {
+ { name = 'cmdline' }
+ })
+})
+
+-- Setup lspconfig.
+local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
+local lspconfig = require('lspconfig')
+
+-- Attaching navic.
+local navic = require("nvim-navic")
+
+local on_attach = function(client, bufnr)
+ if client.server_capabilities.documentSymbolProvider then
+ navic.attach(client, bufnr)
+ end
+end
+
+-- C++/C.
+lspconfig['clangd'].setup {
+ capabilities = capabilities,
+ on_attach = on_attach
+}
+
+-- Python
+lspconfig['pylsp'].setup {
+ capabilities = capabilities,
+ on_attach = on_attach
+}