Skip to content

Commit 6f0047a

Browse files
committed
[cmp] Use lspkind to display symbols
1 parent 0d4673b commit 6f0047a

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

lua/custom/plugins/nvim-cmp.lua

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ return { -- Autocompletion
2323
'hrsh7th/cmp-nvim-lsp',
2424
'hrsh7th/cmp-path',
2525
'Exafunction/codeium.nvim',
26-
'brenoprata10/nvim-highlight-colors',
26+
-- lspkind
27+
'onsails/lspkind.nvim',
2728

2829
-- If you want to add a bunch of pre-configured snippets,
2930
-- you can use this plugin to help you. It even has snippets
@@ -36,35 +37,37 @@ return { -- Autocompletion
3637
local cmp = require 'cmp'
3738
local luasnip = require 'luasnip'
3839
luasnip.config.setup {}
39-
local nvim_highlight_colors = require("nvim-highlight-colors")
4040

4141
-- Controls how the completion items appear
42-
-- Prefix items by type
43-
-- Display tailwindcss colors as a square
44-
local cmp_formatter = function(entry, vim_item)
45-
-- vim_item as processed by tailwindcss-colorizer-cmp
46-
vim_item = nvim_highlight_colors.format(entry, vim_item)
42+
-- lspkind formatter (icons similar to vscode)
43+
local lspkind = require("lspkind")
44+
local cmp_lspkind = lspkind.cmp_format({
45+
mode = 'symbol', -- show only symbol annotations
46+
maxwidth = {
47+
-- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
48+
-- can also be a function to dynamically calculate max width such as
49+
-- menu = function() return math.floor(0.45 * vim.o.columns) end,
50+
menu = 50, -- leading text (labelDetails)
51+
abbr = 50, -- actual suggestion item
52+
},
53+
symbol_map = { Codeium = "", },
54+
ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
55+
show_labelDetails = true, -- show labelDetails in menu. Disabled by default
4756

48-
-- change menu (name of source)
49-
vim_item.menu = ({
50-
nvim_lsp = "[LSP]",
51-
buffer = "[Buf]",
52-
path = "[Path]",
53-
emoji = "[Emoji]",
54-
luasnip = "[LuaSnip]",
55-
vsnip = "[VSCode Snippet]",
56-
calc = "[Calc]",
57-
spell = "[Spell]",
58-
Codeium = "[Codeium]",
59-
})[entry.source.name]
57+
-- The function below will be called before any actual modifications from lspkind
58+
-- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
59+
before = function (entry, vim_item)
60+
-- ...
6061
return vim_item
61-
end
62+
end
63+
})
6264

6365
cmp.setup {
6466
formatting = {
6567
-- changing the order of fields so the icon is the first
6668
fields = { "menu", "abbr", "kind" },
67-
format = cmp_formatter,
69+
-- format = cmp_formatter,
70+
format = cmp_lspkind
6871
},
6972
snippet = {
7073
expand = function(args)

0 commit comments

Comments
 (0)