feat(lsp): improve logging (#15636)

* Simplify rpc encode/decode messages to rpc.send/rcp.receive
* Make missing handlers message throw a warning
* Clean up formatting style in log
* Move all non-RPC loop messages to trace instead of debug
* Add format func option to log to allow newlines in per log entry
This commit is contained in:
Michael Lingelbach
2021-09-15 11:35:04 -07:00
committed by Justin M. Keyes
parent 27bac13be6
commit 7b1315fe61
4 changed files with 27 additions and 14 deletions

View File

@@ -419,7 +419,7 @@ M['window/logMessage'] = function(_, result, ctx, _)
log.error(message)
elseif message_type == protocol.MessageType.Warning then
log.warn(message)
elseif message_type == protocol.MessageType.Info then
elseif message_type == protocol.MessageType.Info or message_type == protocol.MessageType.Log then
log.info(message)
else
log.debug(message)
@@ -449,7 +449,7 @@ end
-- Add boilerplate error validation and logging for all of these.
for k, fn in pairs(M) do
M[k] = function(err, result, ctx, config)
local _ = log.debug() and log.debug('default_handler', ctx.method, {
local _ = log.trace() and log.trace('default_handler', ctx.method, {
err = err, result = result, ctx=vim.inspect(ctx), config = config
})