1- local util = require ( ' lsp-status/util' )
2- local redraw = require ( ' lsp-status/redraw' )
1+ local util = require ' lsp-status/util'
2+ local redraw = require ' lsp-status/redraw'
33
44local clients = {}
55local messages = {}
6- local function init (_messages , _ ) messages = _messages end
6+ local function init (_messages , _ )
7+ messages = _messages
8+ end
79
810-- Unregister stopped clients
911local function unregister_client (id )
@@ -22,28 +24,33 @@ local function progress_callback(_, msg, ctx)
2224 title = val .title ,
2325 message = val .message ,
2426 percentage = val .percentage ,
25- spinner = 1
27+ spinner = 1 ,
2628 }
2729 elseif val .kind == ' report' then
2830 messages [client_id ].progress [msg .token ].message = val .message
2931 messages [client_id ].progress [msg .token ].percentage = val .percentage
30- messages [client_id ].progress [msg .token ].spinner =
31- messages [client_id ].progress [msg .token ].spinner + 1
32+ messages [client_id ].progress [msg .token ].spinner = messages [client_id ].progress [msg .token ].spinner + 1
3233 elseif val .kind == ' end' then
3334 if messages [client_id ].progress [msg .token ] == nil then
34- vim .api .nvim_command (' echohl WarningMsg' )
35- vim .api .nvim_command (
36- ' echom "[lsp-status] Received `end` message with no corresponding `begin` from ' ..
37- clients [client_id ] .. ' !"' )
38- vim .api .nvim_command (' echohl None' )
35+ vim .api .nvim_command ' echohl WarningMsg'
36+ if clients [client_id ] ~= nil then
37+ vim .api .nvim_command (
38+ ' echom "[lsp-status] Received `end` message with no corresponding `begin` from '
39+ .. clients [client_id ]
40+ .. ' !"'
41+ )
42+ else
43+ vim .api .nvim_command ' echom "[lsp-status] Received `end` message with no corresponding `begin` and nil client!'
44+ end
45+ vim .api .nvim_command ' echohl None'
3946 else
4047 messages [client_id ].progress [msg .token ].message = val .message
4148 messages [client_id ].progress [msg .token ].done = true
4249 messages [client_id ].progress [msg .token ].spinner = nil
4350 end
4451 end
4552 else
46- table.insert (messages [client_id ], {content = val , show_once = true , shown = 0 })
53+ table.insert (messages [client_id ], { content = val , show_once = true , shown = 0 })
4754 end
4855
4956 redraw .redraw ()
@@ -65,34 +72,42 @@ local function get_messages()
6572 message = ctx .message ,
6673 percentage = ctx .percentage ,
6774 progress = true ,
68- spinner = ctx .spinner
75+ spinner = ctx .spinner ,
6976 })
7077
71- if ctx .done then table.insert (progress_remove , {client = client , token = token }) end
78+ if ctx .done then
79+ table.insert (progress_remove , { client = client , token = token })
80+ end
7281 end
7382
7483 for i , msg in ipairs (data .messages ) do
7584 if msg .show_once then
7685 msg .shown = msg .shown + 1
77- if msg .shown > 1 then table.insert (msg_remove , {client = client , idx = i }) end
86+ if msg .shown > 1 then
87+ table.insert (msg_remove , { client = client , idx = i })
88+ end
7889 end
7990
80- table.insert (new_messages , {name = data .name , content = msg .content })
91+ table.insert (new_messages , { name = data .name , content = msg .content })
8192 end
8293
8394 if next (data .status ) ~= nil then
8495 table.insert (new_messages , {
8596 name = data .name ,
8697 content = data .status .content ,
8798 uri = data .status .uri ,
88- status = true
99+ status = true ,
89100 })
90101 end
91102 end
92103 end
93104
94- for _ , item in ipairs (msg_remove ) do table.remove (messages [item .client ].messages , item .idx ) end
95- for _ , item in ipairs (progress_remove ) do messages [item .client ].progress [item .token ] = nil end
105+ for _ , item in ipairs (msg_remove ) do
106+ table.remove (messages [item .client ].messages , item .idx )
107+ end
108+ for _ , item in ipairs (progress_remove ) do
109+ messages [item .client ].progress [item .token ] = nil
110+ end
96111 return new_messages
97112end
98113
@@ -116,7 +131,7 @@ local M = {
116131 register_progress = register_progress ,
117132 register_client = register_client ,
118133 _init = init ,
119- capabilities = capabilities
134+ capabilities = capabilities ,
120135}
121136
122137return M
0 commit comments