@@ -60,10 +60,26 @@ local function get_completion_context(params)
6060 return word , trigger_char , line
6161end
6262
63- local function supports_kind_icons ()
64- -- only blink.cmp supports kind icons currently, so we check for its presence
65- local has_blink_cmp = pcall (require , ' blink.cmp' )
66- return has_blink_cmp
63+ local function ensure_custom_kind (source_name , kind_icon )
64+ -- Start custom kinds from 100 to avoid conflicting with standard LSP kinds (1-25)
65+ local KIND_OFFSET = 100
66+ local kind_name = ' Opencode' .. (source_name :gsub (' ^%l' , string.upper ))
67+
68+ -- If we haven't registered this custom kind yet
69+ if not vim .lsp .protocol .CompletionItemKind [kind_name ] then
70+ -- Find the next available integer ID
71+ local next_id = KIND_OFFSET
72+ while vim .lsp .protocol .CompletionItemKind [next_id ] do
73+ next_id = next_id + 1
74+ end
75+
76+ -- Register both string->int and int->string mappings
77+ vim .lsp .protocol .CompletionItemKind [kind_name ] = next_id
78+ -- The completion UI will display this exact string in the "Kind" column
79+ vim .lsp .protocol .CompletionItemKind [next_id ] = (kind_icon and kind_icon .. ' ' or ' ' ) .. kind_name
80+ end
81+
82+ return vim .lsp .protocol .CompletionItemKind [kind_name ]
6783end
6884
6985--- Convert opencode CompletionItem to LSP CompletionItem
7288--- @return lsp.CompletionItem
7389local function to_lsp_item (item , index )
7490 local source = require (' opencode.ui.completion' ).get_source_by_name (item .source_name )
91+ local custom_kind = ensure_custom_kind (item .source_name , item .kind_icon )
7592
7693 local lsp_item = {
77- label = ( supports_kind_icons () and ' ' or ( item . kind_icon .. ' ' )) .. item .label ,
78- kind = vim . lsp . protocol . CompletionItemKind . Text ,
79- kind_icon = supports_kind_icons () and item .kind_icon or nil , -- Only include kind_icon if supported
94+ label = item .label ,
95+ kind = custom_kind ,
96+ kind_icon = item .kind_icon , -- Keep for plugins that read custom fields (like blink.cmp)
8097 kind_hl = item .kind_hl ,
8198 detail = item .detail ,
8299 documentation = item .documentation and {
0 commit comments