From 5b933613cc741026263825e8ae79876d19643239 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 29 Jul 2022 20:41:35 +0200 Subject: support window/showMessage notifications Introduce a new configuration message_level to control the messages displayed. The option message_level ranges from 1 - 4 (Error - Log) and corresponds to LSP's MessageType namespace. --- init.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'init.lua') diff --git a/init.lua b/init.lua index ba87236..299620d 100644 --- a/init.lua +++ b/init.lua @@ -75,6 +75,10 @@ local lspc = { -- style used by lspc to highlight the diagnostic range -- 60% solarized red diagnostic_style = 'back:#e3514f', + + -- message level to show in the UI when eceiving messages from the server + -- Error = 1, Warning = 2, Info = 3, Log = 4 + message_level = 3, } -- Forward declaration of lspc_err to use it in capture_cmd @@ -935,11 +939,25 @@ local function lspc_handle_publish_diagnostics(ls, uri, diagnostics) end end +local lsp_message_types = {'Error', 'Warning', 'Info', 'Log'} +-- show a message from the server in the UI +local function lspc_handle_show_message(show_message_params) + if show_message_params.type > lspc.message_level then + return + end + + vis:message('--- language server message ---') + local level = lsp_message_types[show_message_params.type] or 'Unknown' + vis:message(level .. ': ' .. show_message_params.message) +end + local function ls_handle_notification(ls, notification) -- luacheck: no unused args local method = notification.method if method == 'textDocument/publishDiagnostics' then lspc_handle_publish_diagnostics(ls, notification.params.uri, notification.params.diagnostics) + elseif method == 'window/showMessage' then + lspc_handle_show_message(notification.params) end end -- cgit v1.2.3