Skip to content

Commit 57abdb8

Browse files
feat: support detail only in doc window (#147)
1 parent 0f5f484 commit 57abdb8

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

lua/blink/cmp/windows/documentation.lua

+20-12
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,22 @@ function docs.show_item(item)
4949
-- todo: only resolve if documentation does not exist
5050
sources.resolve(item, function(resolved_item)
5151
item = resolved_item or item
52-
if item.documentation == nil then
52+
if item.documentation == nil and item.detail == nil then
5353
docs.win:close()
5454
return
5555
end
5656

5757
local detail_lines = {}
5858
if item.detail and item.detail ~= '' then detail_lines = utils.split_lines(item.detail) end
5959

60-
local doc = type(item.documentation) == 'string' and item.documentation or item.documentation.value
61-
local doc_lines = utils.split_lines(doc)
62-
if type(item.documentation) ~= 'string' and item.documentation.kind == 'markdown' then
63-
-- if the rendering seems bugged, it's likely due to this function
64-
doc_lines = utils.combine_markdown_lines(doc_lines)
60+
local doc_lines = {}
61+
if item.documentation ~= nil then
62+
local doc = type(item.documentation) == 'string' and item.documentation or item.documentation.value
63+
doc_lines = utils.split_lines(doc)
64+
if type(item.documentation) ~= 'string' and item.documentation.kind == 'markdown' then
65+
-- if the rendering seems bugged, it's likely due to this function
66+
doc_lines = utils.combine_markdown_lines(doc_lines)
67+
end
6568
end
6669

6770
local combined_lines = vim.list_extend({}, detail_lines)
@@ -75,13 +78,18 @@ function docs.show_item(item)
7578
vim.api.nvim_buf_clear_namespace(docs.win:get_buf(), require('blink.cmp.config').highlight.ns, 0, -1)
7679
if #detail_lines > 0 then
7780
utils.highlight_with_treesitter(docs.win:get_buf(), vim.bo.filetype, 0, #detail_lines)
78-
vim.api.nvim_buf_set_extmark(docs.win:get_buf(), require('blink.cmp.config').highlight.ns, #detail_lines, 0, {
79-
virt_text = { { string.rep('', docs.win.config.max_width) } },
80-
virt_text_pos = 'overlay',
81-
hl_eol = true,
82-
hl_group = 'BlinkCmpDocDetail',
83-
})
81+
82+
-- Only add the separator if there are documentation lines (otherwise only display the detail)
83+
if #doc_lines > 0 then
84+
vim.api.nvim_buf_set_extmark(docs.win:get_buf(), require('blink.cmp.config').highlight.ns, #detail_lines, 0, {
85+
virt_text = { { string.rep('', docs.win.config.max_width) } },
86+
virt_text_pos = 'overlay',
87+
hl_eol = true,
88+
hl_group = 'BlinkCmpDocDetail',
89+
})
90+
end
8491
end
92+
8593
utils.highlight_with_treesitter(docs.win:get_buf(), 'markdown', #detail_lines + 1, #detail_lines + 1 + #doc_lines)
8694

8795
if autocomplete.win:get_win() then

0 commit comments

Comments
 (0)