summaryrefslogtreecommitdiffstatshomepage
path: root/nvim/lua/plugins/cmp.lua
blob: 1a1386342b0dfe51a8b36caca90f7d7a8d2112e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
local status_ok, cmp = pcall(require, "cmp")
if not status_ok then
  return
end

-- Require function for tab to work with LUA-SNIP
local has_words_before = function()
    local line, col = unpack(vim.api.nvim_win_get_cursor(0))
    return col ~= 0 and
               vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col,                                                                          col)
                   :match("%s") == nil
end

cmp.setup({
  completion = {
    completeopt = 'menu,menuone,noinsert',
  },
  snippet = {
    expand = function(args) require('luasnip').lsp_expand(args.body) end
  },
  mapping = {
    ['<C-p>'] = cmp.mapping.select_prev_item(),
    ['<C-n>'] = cmp.mapping.select_next_item(),
    -- Add tab support
    ['<S-Tab>'] = cmp.mapping.select_prev_item(),
    ['<Tab>'] = cmp.mapping.select_next_item(),
    ['<C-d>'] = cmp.mapping.scroll_docs(-4),
    ['<C-u>'] = 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,
    })
  },
  formatting = {
    format = function(entry, vim_item)
      -- fancy icons and a name of kind
      vim_item.kind = require("lspkind").presets.default[vim_item.kind]
      -- set a name for each source
      vim_item.menu = ({
        buffer = "[Buff]",
        nvim_lsp = "[LSP]",
        luasnip = "[LuaSnip]",
        nvim_lua = "[Lua]",
        latex_symbols = "[Latex]"
      })[entry.source.name]
      return vim_item
    end
  },
  sources = {
    {name = 'nvim_lsp'},
    {name = 'nvim_lua'},
    {name = 'path'},
    {name = 'luasnip'},
    {name = 'buffer', keyword_length = 1},
    {name = 'calc'              }
  },
  experimental = {
      -- ghost_text = true,
  }

})



-- local luasnip = require("luasnip")

-- local source_mapping = {
--   nvim_lsp = "[LSP]",
-- 	nvim_lua = "[Lua]",
-- 	path = "[Path]",
-- 	buffer = "[Buffer]",
-- 	luasnip = "[LuaSnip]",
-- 	nvim_lsp_signature_help = "[LspSignatureHelp]",
-- 	calc = "[Calc]",
-- }

-- cmp.setup({
--   snippet = {
--     expand = function(args) require('luasnip').lsp_expand(args.body) end
--   },

--   mapping = {
--     ['<C-p>'] = cmp.mapping.select_prev_item(),
--     ['<C-n>'] = cmp.mapping.select_next_item(),
--     -- Add tab support
--     ['<S-Tab>'] = cmp.mapping.select_prev_item(),
--     ['<Tab>'] = cmp.mapping.select_next_item(),
--     ['<C-d>'] = cmp.mapping.scroll_docs(-4),
--     ['<C-u>'] = 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,
--     })
--   },

-- 	formatting = {
-- 		format = function(entry, vim_item)
-- 			vim_item.kind = require("lspkind").presets.default[vim_item.kind]
-- 			local menu = source_mapping[entry.source.name]
-- 			vim_item.menu = menu
-- 			return vim_item
-- 		end,
-- 	},
--   -- Installed sources
-- 	sources = {
--     -- { name = 'path' },
-- 		{ name = "nvim_lsp" },
-- 		{ name = "nvim_lua" },
--     { name = 'path' },
-- 		{ name = "luasnip" },
-- 		{ name = "buffer", keyword_length = 1 },
--     { name = 'nvim_lsp_signature_help' },
--     { name = 'calc' },
-- 	},
-- })