@@ -3,37 +3,56 @@ local function has_words_before()
33 return col ~= 0 and vim .api .nvim_buf_get_lines (0 , line - 1 , line , true )[1 ]:sub (col , col ):match " %s" == nil
44end
55
6- local function get_icon_provider ()
7- local _ , mini_icons = pcall (require , " mini.icons" )
8- if _G .MiniIcons then
9- return function (kind ) return mini_icons .get (" lsp" , kind or " " ) end
10- end
11- local lspkind_avail , lspkind = pcall (require , " lspkind" )
12- if lspkind_avail then
13- return function (kind ) return lspkind .symbolic (kind , { mode = " symbol" }) end
14- end
15- end
16- --- @type function | false | nil
17- local icon_provider = false
6+ --- @type function ?
7+ local icon_provider
188
19- local function get_icon (ctx )
20- ctx .kind_hl_group = " BlinkCmpKind" .. ctx .kind
21- if ctx .item .source_name == " LSP" then
22- local item_doc , color_item = ctx .item .documentation , nil
23- if item_doc then
24- local highlight_colors_avail , highlight_colors = pcall (require , " nvim-highlight-colors" )
25- color_item = highlight_colors_avail and highlight_colors .format (item_doc , { kind = ctx .kind })
9+ local function get_icon (CTX )
10+ if not icon_provider then
11+ local base = function (ctx ) ctx .kind_hl_group = " BlinkCmpKind" .. ctx .kind end
12+ local _ , mini_icons = pcall (require , " mini.icons" )
13+ if _G .MiniIcons then
14+ icon_provider = function (ctx )
15+ base (ctx )
16+ if ctx .item .source_name == " LSP" then
17+ local item_doc , color_item = ctx .item .documentation , nil
18+ if item_doc then
19+ local highlight_colors_avail , highlight_colors = pcall (require , " nvim-highlight-colors" )
20+ color_item = highlight_colors_avail and highlight_colors .format (item_doc , { kind = ctx .kind })
21+ end
22+ local icon , hl = mini_icons .get (" lsp" , ctx .kind or " " )
23+ if icon then
24+ ctx .kind_icon = icon
25+ ctx .kind_hl_group = hl
26+ end
27+ if color_item and color_item .abbr and color_item .abbr_hl_group then
28+ ctx .kind_icon , ctx .kind_hl_group = color_item .abbr , color_item .abbr_hl_group
29+ end
30+ elseif ctx .item .source_name == " Path" then
31+ ctx .kind_icon , ctx .kind_hl_group = mini_icons .get (ctx .kind == " Folder" and " directory" or " file" , ctx .label )
32+ end
33+ end
2634 end
27- if icon_provider == false then icon_provider = get_icon_provider () end
28- if icon_provider then
29- local icon = icon_provider (ctx .kind )
30- if icon then ctx .kind_icon = icon end
31- end
32- if color_item and color_item .abbr and color_item .abbr_hl_group then
33- ctx .kind_icon , ctx .kind_hl_group = color_item .abbr , color_item .abbr_hl_group
35+ local lspkind_avail , lspkind = pcall (require , " lspkind" )
36+ if lspkind_avail then
37+ icon_provider = function (ctx )
38+ base (ctx )
39+ if ctx .item .source_name == " LSP" then
40+ local item_doc , color_item = ctx .item .documentation , nil
41+ if item_doc then
42+ local highlight_colors_avail , highlight_colors = pcall (require , " nvim-highlight-colors" )
43+ color_item = highlight_colors_avail and highlight_colors .format (item_doc , { kind = ctx .kind })
44+ end
45+ local icon = lspkind .symbolic (ctx .kind , { mode = " symbol" })
46+ if icon then ctx .kind_icon = icon end
47+ if color_item and color_item .abbr and color_item .abbr_hl_group then
48+ ctx .kind_icon , ctx .kind_hl_group = color_item .abbr , color_item .abbr_hl_group
49+ end
50+ end
51+ end
3452 end
53+ icon_provider = base
3554 end
36- return ctx
55+ icon_provider ( CTX )
3756end
3857
3958return {
@@ -81,7 +100,10 @@ return {
81100 get_icon (ctx )
82101 return ctx .kind_icon .. ctx .icon_gap
83102 end ,
84- highlight = function (ctx ) return get_icon (ctx ).kind_hl_group end ,
103+ highlight = function (ctx )
104+ get_icon (ctx )
105+ return ctx .kind_hl_group
106+ end ,
85107 },
86108 },
87109 },
@@ -137,6 +159,5 @@ return {
137159 { " hrsh7th/nvim-cmp" , enabled = false },
138160 { " rcarriga/cmp-dap" , enabled = false },
139161 { " L3MON4D3/LuaSnip" , enabled = false },
140- { " onsails/lspkind.nvim" , enabled = false },
141162 },
142163}
0 commit comments