From da978e3f535de05ad800564231336ec17f1a33fd Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 29 Oct 2022 21:23:05 +1100 Subject: [PATCH] allow style_markdown apply to hover --- lua/navigator/hover.lua | 34 +++++++++++++++++++++++++++++ lua/navigator/lspclient/mapping.lua | 4 +++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 lua/navigator/hover.lua diff --git a/lua/navigator/hover.lua b/lua/navigator/hover.lua new file mode 100644 index 0000000..d490ca8 --- /dev/null +++ b/lua/navigator/hover.lua @@ -0,0 +1,34 @@ +local lsp = vim.lsp +local util = lsp.util +local M = {} +function M.handler(_, result, ctx, config) + config = config or {} + config.focus_id = ctx.method + if not (result and result.contents) then + vim.notify('No information available') + return + end + local markdown_lines = util.convert_input_to_markdown_lines(result.contents) + markdown_lines = util.trim_empty_lines(markdown_lines) + if vim.tbl_isempty(markdown_lines) then + vim.notify('No information available') + return + end + + local opts = {} + opts.wrap = true -- wrapping by default + opts.stylize_markdown = true + opts.focus = true + + local contents = lsp.util._trim(markdown_lines, opts) + + -- applies the syntax and sets the lines to the buffer + local bufnr, winnr = util.open_floating_preview(markdown_lines, 'markdown', config) + + vim.api.nvim_buf_set_option(bufnr, 'modifiable', true) + contents = lsp.util.stylize_markdown(bufnr, contents, opts) + vim.api.nvim_buf_set_option(bufnr, 'modifiable', false) + return bufnr, winnr +end + +return M diff --git a/lua/navigator/lspclient/mapping.lua b/lua/navigator/lspclient/mapping.lua index a7980e6..fc313b3 100644 --- a/lua/navigator/lspclient/mapping.lua +++ b/lua/navigator/lspclient/mapping.lua @@ -405,7 +405,9 @@ function M.setup(attach_opts) border_style = double end if _NgConfigValues.lsp.hover then - vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = border_style }) + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(require('navigator.hover').handler, { + border = border_style, + }) end if cap.documentFormattingProvider then log('formatting enabled setup hdl')