From 85ace3c4355d7bb9f981b9d24a84c790347575c5 Mon Sep 17 00:00:00 2001 From: git-bruh Date: Mon, 1 Apr 2024 23:33:07 +0530 Subject: _show_markdown_message: helper for markdown info --- init.lua | 21 ++++++++++++++++----- lspc.lua | 8 ++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/init.lua b/init.lua index 301fb64..4eaed71 100644 --- a/init.lua +++ b/init.lua @@ -822,6 +822,14 @@ local function lspc_handle_completion_method_response(win, result, old_pos) lspc_err('Unsupported completion') end +local function _show_markdown_message(msg) + vis:command("open") + vis:command("set syntax markdown") + + vis.win.file:insert(0, msg) + vis.win.selection.pos = 0 +end + local function lspc_handle_hover_method_response(win, result, old_pos) if not result or not result.contents then lspc_warn('no hover available') @@ -829,13 +837,14 @@ local function lspc_handle_hover_method_response(win, result, old_pos) end local sel = vis_pos_to_sel(win, old_pos) - local hover_header = - '--- hover: ' .. (win.file.path or '') .. ':' .. sel.line .. ', ' .. sel.col .. ' ---' - local hover_msg = '' -- result is MarkedString[] if type(result.contents) == 'table' and #result.contents > 0 then lspc.log('hover returned list of length ' .. #result.contents) + + local hover_header = '--- hover: ' .. (win.file.path or '') .. ':' .. sel.line .. ', ' .. sel.col .. ' ---' + local hover_msg = '' + for i, v in ipairs(result.contents) do if i == 1 then hover_msg = v.value or v @@ -843,11 +852,13 @@ local function lspc_handle_hover_method_response(win, result, old_pos) hover_msg = hover_msg .. '\n---\n' .. (v.value or v) end end + + vis:message(hover_header .. '\n' .. hover_msg) -- result is either MarkedString or MarkupContent else - hover_msg = result.contents.value or result.contents + _show_markdown_message(result.contents.value or result.contents) end - vis:message(hover_header .. '\n' .. hover_msg) + end local function lspc_handle_signature_help_method_response(win, result, call_pos) diff --git a/lspc.lua b/lspc.lua index aa51560..1af21a5 100644 --- a/lspc.lua +++ b/lspc.lua @@ -55,7 +55,7 @@ local lspc = { -- --- ClientCapabilities we tell the language server when calling "initialize" -- -local supported_markup_kind = {'plaintext'} +local supported_markup_kind = {'markdown'} local goto_methods_capabilities = { linkSupport = true, @@ -69,14 +69,14 @@ local client_capabilites = { }, textDocument = { synchronization = {dynamicRegistration = false, didSave = true}, - -- ask the server to send us only plaintext completionItems + -- ask the server to send us only markdown completionItems completion = { dynamicRegistration = false, completionItem = {documentationFormat = supported_markup_kind}, }, - -- ask the server to send us only plaintext hover results + -- ask the server to send us only markdown hover results hover = {dynamicRegistration = false, contentFormat = supported_markup_kind}, - -- ask the server to send us only plaintext signatureHelp results + -- ask the server to send us only markdown signatureHelp results signatureHelp = { dynamicRegistration = false, signatureInformation = {documentationFormat = supported_markup_kind}, -- cgit v1.2.3