Skip to content

Commit 05229dd

Browse files
committed
feat: stylize markdown in documentation window
1 parent 4883420 commit 05229dd

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lua/blink/cmp/windows/documentation.lua

+13-5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function docs.show_item(item)
6161
table.insert(doc_lines, s)
6262
end
6363
table.insert(doc_lines, '```')
64+
table.insert(doc_lines, '---')
6465
end
6566

6667
local doc = type(item.documentation) == 'string' and item.documentation or item.documentation.value
@@ -70,15 +71,22 @@ function docs.show_item(item)
7071
vim.api.nvim_buf_set_lines(docs.win:get_buf(), 0, -1, true, doc_lines)
7172
vim.api.nvim_set_option_value('modified', false, { buf = docs.win:get_buf() })
7273

73-
local filetype = item.documentation.kind == 'markdown' and 'markdown' or 'plaintext'
74-
if filetype ~= vim.api.nvim_get_option_value('filetype', { buf = docs.win:get_buf() }) then
75-
vim.api.nvim_set_option_value('filetype', filetype, { buf = docs.win:get_buf() })
76-
end
77-
7874
if autocomplete.win:get_win() then
7975
docs.win:open()
8076
docs.update_position()
8177
end
78+
79+
-- use the built-in markdown styling
80+
-- NOTE: according to https://github.com/Saghen/blink.cmp/pull/33#issuecomment-2400195950
81+
-- it's possible for this to fail so we call it safely
82+
pcall(
83+
function()
84+
vim.lsp.util.stylize_markdown(docs.win:get_buf(), doc_lines, {
85+
height = vim.api.nvim_win_get_height(docs.win:get_win()),
86+
width = vim.api.nvim_win_get_width(docs.win:get_win()),
87+
})
88+
end
89+
)
8290
end)
8391
end
8492

0 commit comments

Comments
 (0)