Skip to content

Commit

Permalink
fix exception when attempt to concatenate a nil value (#80)
Browse files Browse the repository at this point in the history
* fix exception when attempt to concatenate a nil value

* Add message for nil client and format

Co-authored-by: Wil Thomason <wil.thomason@gmail.com>
  • Loading branch information
jdssl and wbthomason committed Aug 3, 2022
1 parent 445dd48 commit 54f48eb
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions lua/lsp-status/messaging.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
local util = require('lsp-status/util')
local redraw = require('lsp-status/redraw')
local util = require 'lsp-status/util'
local redraw = require 'lsp-status/redraw'

local clients = {}
local messages = {}
local function init(_messages, _) messages = _messages end
local function init(_messages, _)
messages = _messages
end

-- Unregister stopped clients
local function unregister_client(id)
Expand All @@ -22,28 +24,33 @@ local function progress_callback(_, msg, ctx)
title = val.title,
message = val.message,
percentage = val.percentage,
spinner = 1
spinner = 1,
}
elseif val.kind == 'report' then
messages[client_id].progress[msg.token].message = val.message
messages[client_id].progress[msg.token].percentage = val.percentage
messages[client_id].progress[msg.token].spinner =
messages[client_id].progress[msg.token].spinner + 1
messages[client_id].progress[msg.token].spinner = messages[client_id].progress[msg.token].spinner + 1
elseif val.kind == 'end' then
if messages[client_id].progress[msg.token] == nil then
vim.api.nvim_command('echohl WarningMsg')
vim.api.nvim_command(
'echom "[lsp-status] Received `end` message with no corresponding `begin` from ' ..
clients[client_id] .. '!"')
vim.api.nvim_command('echohl None')
vim.api.nvim_command 'echohl WarningMsg'
if clients[client_id] ~= nil then
vim.api.nvim_command(
'echom "[lsp-status] Received `end` message with no corresponding `begin` from '
.. clients[client_id]
.. '!"'
)
else
vim.api.nvim_command 'echom "[lsp-status] Received `end` message with no corresponding `begin` and nil client!'
end
vim.api.nvim_command 'echohl None'
else
messages[client_id].progress[msg.token].message = val.message
messages[client_id].progress[msg.token].done = true
messages[client_id].progress[msg.token].spinner = nil
end
end
else
table.insert(messages[client_id], {content = val, show_once = true, shown = 0})
table.insert(messages[client_id], { content = val, show_once = true, shown = 0 })
end

redraw.redraw()
Expand All @@ -65,34 +72,42 @@ local function get_messages()
message = ctx.message,
percentage = ctx.percentage,
progress = true,
spinner = ctx.spinner
spinner = ctx.spinner,
})

if ctx.done then table.insert(progress_remove, {client = client, token = token}) end
if ctx.done then
table.insert(progress_remove, { client = client, token = token })
end
end

for i, msg in ipairs(data.messages) do
if msg.show_once then
msg.shown = msg.shown + 1
if msg.shown > 1 then table.insert(msg_remove, {client = client, idx = i}) end
if msg.shown > 1 then
table.insert(msg_remove, { client = client, idx = i })
end
end

table.insert(new_messages, {name = data.name, content = msg.content})
table.insert(new_messages, { name = data.name, content = msg.content })
end

if next(data.status) ~= nil then
table.insert(new_messages, {
name = data.name,
content = data.status.content,
uri = data.status.uri,
status = true
status = true,
})
end
end
end

for _, item in ipairs(msg_remove) do table.remove(messages[item.client].messages, item.idx) end
for _, item in ipairs(progress_remove) do messages[item.client].progress[item.token] = nil end
for _, item in ipairs(msg_remove) do
table.remove(messages[item.client].messages, item.idx)
end
for _, item in ipairs(progress_remove) do
messages[item.client].progress[item.token] = nil
end
return new_messages
end

Expand All @@ -116,7 +131,7 @@ local M = {
register_progress = register_progress,
register_client = register_client,
_init = init,
capabilities = capabilities
capabilities = capabilities,
}

return M

0 comments on commit 54f48eb

Please sign in to comment.