From 88fc8c77a470ff80892b20df44c6030b83bd948e Mon Sep 17 00:00:00 2001 From: Charles Danesi Date: Mon, 25 Nov 2024 08:58:28 -0500 Subject: [PATCH] add completion sources --- .config/nvim/lua/plugins/nvim-cmp.lua | 114 +++++++++++++------------- 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-cmp.lua b/.config/nvim/lua/plugins/nvim-cmp.lua index 9ac84e6..00f3e81 100644 --- a/.config/nvim/lua/plugins/nvim-cmp.lua +++ b/.config/nvim/lua/plugins/nvim-cmp.lua @@ -1,82 +1,86 @@ return { - "hrsh7th/nvim-cmp", - event = "InsertEnter", + 'hrsh7th/nvim-cmp', + event = { 'InsertEnter', 'CmdlineEnter' }, dependencies = { - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-nvim-lsp-document-symbol', + 'hrsh7th/cmp-nvim-lsp-signature-help', + 'saadparwaiz1/cmp_luasnip', + 'rafamadriz/friendly-snippets', + 'onsails/lspkind.nvim', { - "L3MON4D3/LuaSnip", - version = "v2.*", - build = "make install_jsregexp", + 'L3MON4D3/LuaSnip', + version = 'v2.*', + build = 'make install_jsregexp', }, - "saadparwaiz1/cmp_luasnip", - "rafamadriz/friendly-snippets", - "onsails/lspkind.nvim", }, config = function() - local cmp = require "cmp" - local luasnip = require "luasnip" - local lspkind = require "lspkind" + local cmp = require('cmp') + local luasnip = require('luasnip') + local lspkind = require('lspkind') - require("luasnip.loaders.from_vscode").lazy_load() + require('luasnip.loaders.from_vscode').lazy_load() - cmp.setup { + cmp.setup({ view = { - entries = "custom", - selection_order = "near_cursor", + entries = 'custom', + selection_order = 'near_cursor', }, completion = { - completeopt = "menu,menuone,preview,noselect", + completeopt = 'menu,menuone,preview,noselect', }, snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, - mapping = cmp.mapping.preset.insert { - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.abort(), - [""] = cmp.mapping.confirm { select = false }, - }, - sources = cmp.config.sources { - { name = "nvim_lsp" }, - { name = "luasnip" }, - { name = "buffer" }, - { name = "path" }, - }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = false }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'buffer' }, + { name = 'path' }, + }), formatting = { - format = lspkind.cmp_format { - mode = "symbol_text", + format = lspkind.cmp_format({ + mode = 'symbol_text', maxwidth = 50, - ellipsis_char = "...", + ellipsis_char = '...', show_labelDetails = true, menu = { -- add name of source to the menu - nvim_lsp = "[LSP]", - nvim_lua = "[Lua]", - luasnip = "[LuaSnip]", - buffer = "[Buffer]", - path = "[Path]", + nvim_lsp = '[LSP]', + nvim_lua = '[Lua]', + luasnip = '[LuaSnip]', + buffer = '[Buffer]', + path = '[Path]', }, - }, + }), }, -- VSCode-like, kind specific highlights - vim.api.nvim_set_hl(0, "CmpItemAbbrDeprecated", { bg = "NONE", strikethrough = true, fg = "#808080" }), - vim.api.nvim_set_hl(0, "CmpItemAbbrMatch", { bg = "NONE", fg = "#569CD6" }), - vim.api.nvim_set_hl(0, "CmpItemAbbrMatchFuzzy", { link = "CmpIntemAbbrMatch" }), - vim.api.nvim_set_hl(0, "CmpItemKindVariable", { bg = "NONE", fg = "#9CDCFE" }), - vim.api.nvim_set_hl(0, "CmpItemKindInterface", { link = "CmpItemKindVariable" }), - vim.api.nvim_set_hl(0, "CmpItemKindText", { link = "CmpItemKindVariable" }), - vim.api.nvim_set_hl(0, "CmpItemKindFunction", { bg = "NONE", fg = "#C586C0" }), - vim.api.nvim_set_hl(0, "CmpItemKindMethod", { link = "CmpItemKindFunction" }), - vim.api.nvim_set_hl(0, "CmpItemKindKeyword", { bg = "NONE", fg = "#D4D4D4" }), - vim.api.nvim_set_hl(0, "CmpItemKindProperty", { link = "CmpItemKindKeyword" }), - vim.api.nvim_set_hl(0, "CmpItemKindUnit", { link = "CmpItemKindKeyword" }), - } + vim.api.nvim_set_hl(0, 'CmpItemAbbrDeprecated', { bg = 'NONE', strikethrough = true, fg = '#4c566a' }), + vim.api.nvim_set_hl(0, 'CmpItemAbbrMatch', { bg = 'NONE', fg = '#81a1c1' }), + vim.api.nvim_set_hl(0, 'CmpItemAbbrMatchFuzzy', { link = 'CmpIntemAbbrMatch' }), + vim.api.nvim_set_hl(0, 'CmpItemKindVariable', { bg = 'NONE', fg = '#88c0d0' }), + vim.api.nvim_set_hl(0, 'CmpItemKindInterface', { link = 'CmpItemKindVariable' }), + vim.api.nvim_set_hl(0, 'CmpItemKindText', { link = 'CmpItemKindVariable' }), + vim.api.nvim_set_hl(0, 'CmpItemKindFunction', { bg = 'NONE', fg = '#b48ead' }), + vim.api.nvim_set_hl(0, 'CmpItemKindMethod', { link = 'CmpItemKindFunction' }), + vim.api.nvim_set_hl(0, 'CmpItemKindKeyword', { bg = 'NONE', fg = '#a3be8c' }), + vim.api.nvim_set_hl(0, 'CmpItemKindProperty', { link = 'CmpItemKindKeyword' }), + vim.api.nvim_set_hl(0, 'CmpItemKindUnit', { link = 'CmpItemKindKeyword' }), + }) end, -} +} \ No newline at end of file