The previous version can cause a stack overflow error since the line before the last end calls itself.
Version 2: It may be a better version:
-- disable LSP info lines
local default_showMessage = vim.lsp.handlers['window/showMessage']
vim.lsp.handlers['window/showMessage'] = function(err, result, ctx)
if not result then
return
end
if result.type == vim.lsp.protocol.MessageType.Info then
return
end
default_showMessage(err, result, ctx)
end