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'
3
3
4
4
local clients = {}
5
5
local messages = {}
6
- local function init (_messages , _ ) messages = _messages end
6
+ local function init (_messages , _ )
7
+ messages = _messages
8
+ end
7
9
8
10
-- Unregister stopped clients
9
11
local function unregister_client (id )
@@ -22,28 +24,33 @@ local function progress_callback(_, msg, ctx)
22
24
title = val .title ,
23
25
message = val .message ,
24
26
percentage = val .percentage ,
25
- spinner = 1
27
+ spinner = 1 ,
26
28
}
27
29
elseif val .kind == ' report' then
28
30
messages [client_id ].progress [msg .token ].message = val .message
29
31
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
32
33
elseif val .kind == ' end' then
33
34
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'
39
46
else
40
47
messages [client_id ].progress [msg .token ].message = val .message
41
48
messages [client_id ].progress [msg .token ].done = true
42
49
messages [client_id ].progress [msg .token ].spinner = nil
43
50
end
44
51
end
45
52
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 })
47
54
end
48
55
49
56
redraw .redraw ()
@@ -65,34 +72,42 @@ local function get_messages()
65
72
message = ctx .message ,
66
73
percentage = ctx .percentage ,
67
74
progress = true ,
68
- spinner = ctx .spinner
75
+ spinner = ctx .spinner ,
69
76
})
70
77
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
72
81
end
73
82
74
83
for i , msg in ipairs (data .messages ) do
75
84
if msg .show_once then
76
85
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
78
89
end
79
90
80
- table.insert (new_messages , {name = data .name , content = msg .content })
91
+ table.insert (new_messages , { name = data .name , content = msg .content })
81
92
end
82
93
83
94
if next (data .status ) ~= nil then
84
95
table.insert (new_messages , {
85
96
name = data .name ,
86
97
content = data .status .content ,
87
98
uri = data .status .uri ,
88
- status = true
99
+ status = true ,
89
100
})
90
101
end
91
102
end
92
103
end
93
104
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
96
111
return new_messages
97
112
end
98
113
@@ -116,7 +131,7 @@ local M = {
116
131
register_progress = register_progress ,
117
132
register_client = register_client ,
118
133
_init = init ,
119
- capabilities = capabilities
134
+ capabilities = capabilities ,
120
135
}
121
136
122
137
return M
0 commit comments