summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/plugins/lspkind.lua
blob: 2a5165fcbcc6ebcac33aeb95fc92b6db6f25cbb2 (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
return {
	{
		'onsails/lspkind.nvim',
		config = function()
			require('lspkind').setup({
				mode = 'text',
				preset = 'default',
			})
		end
	},
	{
		"hrsh7th/nvim-cmp",
		dependencies = {
			"onsails/lspkind.nvim",
			"hrsh7th/cmp-nvim-lsp",
			"hrsh7th/cmp-buffer",
			"hrsh7th/cmp-path",
			"L3MON4D3/LuaSnip",
		},
		event = "InsertEnter",
		config = function()
			vim.api.nvim_set_hl(0, "CmpNormal", { bg = "#32302f" })
			vim.api.nvim_set_hl(0, "PmenuSel",  { bg = "#504945" })
			local cmp = require('cmp')
			local lspkind = require('lspkind')

			cmp.setup({
				snippet = {
					expand = function(args)
						require('luasnip').lsp_expand(args.body)
					end,
				},
				formatting = {
					format = lspkind.cmp_format({
						mode = 'text',
						maxwidth = {
							menu = 50,
							abbr = 50,
						},
						ellipsis_char = '...',
						show_labelDetails = true,
						before = function(entry, vim_item)
							-- Add source name to menu
							vim_item.menu = ({
								nvim_lsp = "[LSP]",
								luasnip = "[LuaSnip]",
								buffer = "[Buffer]",
								path = "[Path]",
							})[entry.source.name]
							return vim_item
						end
					})
				},
				mapping = cmp.mapping.preset.insert({
					['<C-j>'] = cmp.mapping.select_next_item(cmp_select),
					['<C-k>'] = cmp.mapping.select_prev_item(cmp_select),
					['<C-b>'] = cmp.mapping.scroll_docs(-4),
					['<C-f>'] = cmp.mapping.scroll_docs(4),
					['<C-Space>'] = cmp.mapping.complete(),
					['<C-e>'] = cmp.mapping.abort(),
					['<CR>'] = cmp.mapping.confirm({ select = true }),
				}),
				sources = cmp.config.sources({
					{ name = 'nvim_lsp' },
					{ name = 'luasnip' },
				}, {
						{ name = 'buffer' },
						{ name = 'path' },
					}),
				window = {
					completion = {
						border = 'none',
						winhighlight = "Normal:CmpNormal,FloatBorder:CmpNormal,CursorLine:PmenuSel,Search:None",
					},
					documentation = {
						border = 'none',
						winhighlight = "Normal:CmpNormal,FloatBorder:CmpNormal,CursorLine:PmenuSel,Search:None",
					},
				},
			})
		end,
	},
}