aboutsummaryrefslogtreecommitdiff
path: root/lua/plugins/cmp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/plugins/cmp.lua')
-rw-r--r--lua/plugins/cmp.lua134
1 files changed, 134 insertions, 0 deletions
diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua
new file mode 100644
index 0000000..39c08d7
--- /dev/null
+++ b/lua/plugins/cmp.lua
@@ -0,0 +1,134 @@
+local cmp_status_ok, cmp = pcall(require, "cmp")
+if not cmp_status_ok then
+ return
+end
+
+local lspkind = require("lspkind")
+cmp.setup({
+ formatting = {
+ format = lspkind.cmp_format({
+ mode = "symbol", -- show only symbol annotations
+ maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
+ ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
+
+ -- The function below will be called before any actual modifications from lspkind
+ -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
+ before = function(entry, vim_item)
+ --...
+ return vim_item
+ end,
+ }),
+ },
+})
+
+require("luasnip/loaders/from_vscode").lazy_load()
+
+--   פּ ﯟ  some other good icons
+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 = "",
+}
+
+-- find more here: https://www.nerdfonts.com/cheat-sheet
+
+cmp.setup({
+ snippet = {
+ expand = function(args)
+ require("luasnip").lsp_expand(args.body)
+ end,
+ },
+ mapping = cmp.mapping.preset.insert({
+ ["<C-d>"] = cmp.mapping.scroll_docs(-4),
+ ["<C-f>"] = cmp.mapping.scroll_docs(4),
+ ["<C-Space>"] = cmp.mapping.complete(),
+ ["<C-e>"] = cmp.mapping.close(),
+ ["<CR>"] = cmp.mapping.confirm({
+ behavior = cmp.ConfirmBehavior.Replace,
+ select = true,
+ }),
+ }),
+ sources = cmp.config.sources({
+ { name = "path" },
+ { name = "nvim_lsp", keyword_length = 3 },
+ { name = "buffer", keyword_length = 3 },
+ { name = "luasnip", keyword_length = 4 },
+ { name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=], keyword_length = 3 },
+ --{ name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=] }, --exclamation mark hangs a bit without this
+ --{name = 'luasnip', keyword_length = 2},
+ }),
+ 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]",
+ })[entry.source.name]
+ return vim_item
+ end,
+ },
+ confirm_opts = {
+ behavior = cmp.ConfirmBehavior.Replace,
+ select = false,
+ },
+ window = {
+ documentation = {
+ border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
+ },
+ },
+ experimental = {
+ ghost_text = true,
+ native_menu = false,
+ --view = {
+ -- entries = "native"
+ --},
+ },
+})
+
+vim.cmd([[
+ set completeopt=menuone,noinsert,noselect
+ highlight! default link CmpItemKind CmpItemMenuDefault
+]])
+
+cmp.setup.cmdline("/", {
+ mapping = cmp.mapping.preset.cmdline(),
+ sources = {
+ { name = "buffer" },
+ },
+})
+
+cmp.setup.cmdline(":", {
+ mapping = cmp.mapping.preset.cmdline(),
+ sources = cmp.config.sources({
+ { name = "path" },
+ }, {
+ { name = "cmdline" },
+ }),
+})