Skip to content

Commit d305787

Browse files
committed
Fix #6: Check that end messages had a valid begin before indexing
1 parent d6ad842 commit d305787

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lua/lsp-status/messaging.lua

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local util = require('lsp-status/util')
22

3+
local clients = {}
34
local messages = {}
45
local function init(_messages, _)
56
messages = _messages
@@ -21,9 +22,17 @@ local function progress_callback(_, _, msg, client_id)
2122
messages[client_id].progress[msg.token].percentage = val.percentage
2223
messages[client_id].progress[msg.token].spinner = messages[client_id].progress[msg.token].spinner + 1
2324
elseif val.kind == 'end' then
24-
messages[client_id].progress[msg.token].message = val.message
25-
messages[client_id].progress[msg.token].done = true
26-
messages[client_id].progress[msg.token].spinner = nil
25+
if messages[client_id].progress[msg.token] == nil then
26+
vim.api.nvim_command('echohl WarningMsg')
27+
vim.api.nvim_command(
28+
'echom "[lsp-status] Received `end` message with no corresponding `begin` from ' .. clients[client_id] .. '!"'
29+
)
30+
vim.api.nvim_command('echohl None')
31+
else
32+
messages[client_id].progress[msg.token].message = val.message
33+
messages[client_id].progress[msg.token].done = true
34+
messages[client_id].progress[msg.token].spinner = nil
35+
end
2736
end
2837
else
2938
table.insert(messages[client_id], { content = val, show_once = true, shown = 0 })
@@ -92,6 +101,7 @@ end
92101
-- Client registration for messages
93102
local function register_client(id, name)
94103
util.ensure_init(messages, id, name)
104+
clients[id] = name
95105
end
96106

97107
local capabilities = vim.lsp.protocol.make_client_capabilities()

0 commit comments

Comments
 (0)