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 From efaf185f4368aeb04de0b851f76b5bad020804e7 Mon Sep 17 00:00:00 2001 From: git-bruh Date: Sun, 7 Apr 2024 01:34:52 +0530 Subject: init: show messages not requiring context in a new split --- init.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index 4eaed71..8347899 100644 --- a/init.lua +++ b/init.lua @@ -501,6 +501,13 @@ local function vis_apply_textEdits(win, file, textEdits) win:draw() end +local function _show_message(msg) + vis:command("open") + + vis.win.file:insert(0, msg) + vis.win.selection.pos = 0 +end + -- apply a WorkspaceEdit received from the language server local function vis_apply_workspaceEdit(_, _, workspaceEdit) local file_edits = workspaceEdit.changes @@ -527,7 +534,7 @@ local function vis_apply_workspaceEdit(_, _, workspaceEdit) end end - vis:message(summary) + _show_message(summary) vis:redraw() -- get user confirmation @@ -842,7 +849,7 @@ local function lspc_handle_hover_method_response(win, result, old_pos) 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_header = '--- hover: ' .. (win.file.path or '') .. ': ' .. sel.line .. ', ' .. sel.col .. ' ---' local hover_msg = '' for i, v in ipairs(result.contents) do @@ -853,7 +860,7 @@ local function lspc_handle_hover_method_response(win, result, old_pos) end end - vis:message(hover_header .. '\n' .. hover_msg) + _show_message(hover_header .. '\n' .. hover_msg) -- result is either MarkedString or MarkupContent else _show_markdown_message(result.contents.value or result.contents) @@ -870,7 +877,7 @@ local function lspc_handle_signature_help_method_response(win, result, call_pos) local signatures = result.signatures local sel = vis_pos_to_sel(win, call_pos) - local help_header = '--- signature help: ' .. (win.file.path or '') .. ':' .. sel.line .. ', ' .. + local help_header = '--- signature help: ' .. (win.file.path or '') .. ': ' .. sel.line .. ', ' .. sel.col .. ' ---' -- local help_msg = json.encode(result) @@ -883,7 +890,7 @@ local function lspc_handle_signature_help_method_response(win, result, call_pos) end help_msg = help_msg .. '\n' .. sig_msg end - vis:message(help_header .. help_msg) + _show_message(help_header .. help_msg) end local function lspc_handle_rename_method_response(win, result) @@ -1381,7 +1388,7 @@ local function lspc_show_diagnostic(ls, win, line) end end - local diagnostics_fmt = '%d:%d %s:%s\n' + local diagnostics_fmt = '%d:%d %s: %s\n' local diagnostics_msg = '' for _, diagnostic in ipairs(diagnostics_to_show) do diagnostics_msg = diagnostics_msg .. @@ -1391,7 +1398,7 @@ local function lspc_show_diagnostic(ls, win, line) end if diagnostics_msg ~= '' then - vis:message(diagnostics_msg) + _show_message(diagnostics_msg) else lspc_warn('No diagnostics available for line: ' .. line) end -- cgit v1.2.3 From 0e71c4a1e7aabcad269ffb1cdd3f53da6ef31df4 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 12 Apr 2024 11:10:17 +0200 Subject: make the way messages are presented configurable The two options are either using vis:message (the default) which will keep all messages in the vis message buffer and include a header line to distinguish the different messages. The second option is using open and presenting messages in a separate window supporting syntax highlighting. --- README.md | 2 ++ init.lua | 63 +++++++++++++++++++++++++++++++++++---------------------------- lspc.lua | 4 ++++ 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 27905b3..9948af6 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,8 @@ Available options are: * `highlight_diagnostics = 'line'` - highlight the `range` or `line`number of available diagnostics * `workspace_edit_remember_cursor = true` - restore the primary cursor position after a workspaceEdit * `diagnostic_styles = { error = 'back:red', warning = 'back:yellow', information = 'back:yellow', hint = 'back:yellow', }` - styles used to highlight different diagnostics +* `show_message = 'message'` - how to present information. `'message'`: use `vis:message`; `'open'`: use a new window supporting syntax highlighting. +* `message_level = 3` - the level of shown messages retrieved via `window/showMessage` notifications #### Configure your own Language Server diff --git a/init.lua b/init.lua index 8347899..eaadc1b 100644 --- a/init.lua +++ b/init.lua @@ -501,11 +501,21 @@ local function vis_apply_textEdits(win, file, textEdits) win:draw() end -local function _show_message(msg) - vis:command("open") +local function lspc_show_message(msg, hdr, syntax) + if lspc.show_message == 'message' then + vis:message((hdr or '') .. msg) + + elseif lspc.show_message == 'open' then + vis:command('open') + if syntax then + vis:command('set syntax ' .. syntax) + end - vis.win.file:insert(0, msg) - vis.win.selection.pos = 0 + vis.win.file:insert(0, msg) + vis.win.selection.pos = 0 + else + lspc_err('invalid message configuration "' .. lspc.show_message .. '".') + end end -- apply a WorkspaceEdit received from the language server @@ -534,7 +544,7 @@ local function vis_apply_workspaceEdit(_, _, workspaceEdit) end end - _show_message(summary) + lspc_show_message(summary) vis:redraw() -- get user confirmation @@ -829,14 +839,6 @@ 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') @@ -845,27 +847,30 @@ local function lspc_handle_hover_method_response(win, result, old_pos) local sel = vis_pos_to_sel(win, old_pos) + local hover_header = + '--- hover: ' .. (win.file.path or '') .. ': ' .. sel.line .. ', ' .. sel.col .. ' ---\n' + local hover_msg = '' + -- The most common markup kind in LSP is markdown + local markup_kind = 'markdown' + -- 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 + for i, marked_string in ipairs(result.contents) do if i == 1 then - hover_msg = v.value or v + hover_msg = marked_string.value or marked_string else - hover_msg = hover_msg .. '\n---\n' .. (v.value or v) + hover_msg = hover_msg .. '\n---\n' .. (marked_string.value or marked_string) end end - - _show_message(hover_header .. '\n' .. hover_msg) - -- result is either MarkedString or MarkupContent - else - _show_markdown_message(result.contents.value or result.contents) + else -- result is either MarkedString or MarkupContent + hover_msg = result.contents.value or result.contents + if result.contents.kind and result.contents.kind == 'plaintext' then + markup_kind = 'text' + end end - + lspc_show_message(hover_msg, hover_header, markup_kind) end local function lspc_handle_signature_help_method_response(win, result, call_pos) @@ -878,7 +883,7 @@ local function lspc_handle_signature_help_method_response(win, result, call_pos) local sel = vis_pos_to_sel(win, call_pos) local help_header = '--- signature help: ' .. (win.file.path or '') .. ': ' .. sel.line .. ', ' .. - sel.col .. ' ---' + sel.col .. ' ---\n' -- local help_msg = json.encode(result) local help_msg = '' @@ -890,7 +895,9 @@ local function lspc_handle_signature_help_method_response(win, result, call_pos) end help_msg = help_msg .. '\n' .. sig_msg end - _show_message(help_header .. help_msg) + -- strip first new line from the message + help_msg = help_msg:sub(2) + lspc_show_message(help_msg, help_header) end local function lspc_handle_rename_method_response(win, result) @@ -1398,7 +1405,7 @@ local function lspc_show_diagnostic(ls, win, line) end if diagnostics_msg ~= '' then - _show_message(diagnostics_msg) + lspc_show_message(diagnostics_msg) else lspc_warn('No diagnostics available for line: ' .. line) end diff --git a/lspc.lua b/lspc.lua index 1af21a5..d45811b 100644 --- a/lspc.lua +++ b/lspc.lua @@ -50,6 +50,10 @@ local lspc = { -- message level to show in the UI when receiving messages from the server -- Error = 1, Warning = 2, Info = 3, Log = 4 message_level = 3, + + -- How to present messages to the user. + -- 'message': use vis:message; 'open': use a new split window allowing for syntax highlighting + show_message = 'message', } -- -- cgit v1.2.3