Open FormalSnake opened 1 year ago
i know this is not a bug but its the only issue template
@FormalSnake this will be possible once https://github.com/neovim/neovim/pull/25073 goes in.
Nice! What a coincidence lol
The https://github.com/neovim/neovim/pull/25073 is merged into master, can we expect that nvim-cmp docs will be the same as neovim core hover soon?
@MariaSolOs Thank you for https://github.com/neovim/neovim/pull/25073
This is great!
Alright here's the thing: I had initially envisioned https://github.com/neovim/neovim/pull/25073 to include the public API for the new LSP markdown methods, but because that will involve a larger refactor tracked by https://github.com/neovim/neovim/issues/25272, this will happen in the future. In the meantime, here's a workaround I have in my dotfiles that's inspired by what Noice does.
DISCLAIMER: You shouldn't patch plugins like this or use private (prefixed by _
) methods in Neovim. This will very likely cause your configuration to break and you won't be able to blame anyone about it except for yourself, so use at your own risk.
Still here? Okay here's the code.
--- HACK: Override `vim.lsp.util.stylize_markdown` to use Treesitter.
---@param bufnr integer
---@param contents string[]
---@param opts table
---@return string[]
---@diagnostic disable-next-line: duplicate-set-field
vim.lsp.util.stylize_markdown = function(bufnr, contents, opts)
contents = vim.lsp.util._normalize_markdown(contents, {
width = vim.lsp.util._make_floating_popup_size(contents, opts),
})
vim.bo[bufnr].filetype = 'markdown'
vim.treesitter.start(bufnr)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, contents)
return contents
end
I have extra enhancements in my (publicly available) configuration, but I'll leave that as an exercise for the reader to figure out/find.
I tried it and it looks great, but how do I scroll in the docs without mouse 😅
Mappings in the minimal config from your issue description has bindings to scroll docs:
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
This is particularly important for documentations that make frequent use of
since that can make docs pretty tough to read when they don't get rendered.
Alright here's the thing: I had initially envisioned neovim/neovim#25073 to include the public API for the new LSP markdown methods, but because that will involve a larger refactor tracked by neovim/neovim#25272, this will happen in the future. In the meantime, here's a workaround I have in my dotfiles that's inspired by what Noice does.
DISCLAIMER: You shouldn't patch plugins like this or use private (prefixed by
_
) methods in Neovim. This will very likely cause your configuration to break and you won't be able to blame anyone about it except for yourself, so use at your own risk.Still here? Okay here's the code.
--- HACK: Override `vim.lsp.util.stylize_markdown` to use Treesitter. ---@param bufnr integer ---@param contents string[] ---@param opts table ---@return string[] ---@diagnostic disable-next-line: duplicate-set-field vim.lsp.util.stylize_markdown = function(bufnr, contents, opts) contents = vim.lsp.util._normalize_markdown(contents, { width = vim.lsp.util._make_floating_popup_size(contents, opts), }) vim.bo[bufnr].filetype = 'markdown' vim.treesitter.start(bufnr) vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, contents) return contents end
I have extra enhancements in my (publicly available) configuration, but I'll leave that as an exercise for the reader to figure out/find.
A less hacky workaround. Change vim.lsp.util.stylize_markdown
to a local function:
local stylize_markdown = function(bufnr, contents, opts)
contents = vim.lsp.util._normalize_markdown(contents, {
width = vim.lsp.util._make_floating_popup_size(contents, opts),
})
...
And call it here:
FAQ
Announcement
Minimal reproducible full config
not relevant but
Description
Markdown is not displayed correctly
Steps to reproduce
just use the plugin
Expected behavior
instead of seeing the markdown it should be formatted
Actual behavior
it is not
Additional context
No response