@@ -32,6 +32,21 @@ local function check_cond(cond, client, bufnr)
3232 return true
3333end
3434
35+ --- Add a new LSP progress message to the message queue
36+ --- @param data { client_id : integer , result : lsp.ProgressParams }
37+ function M .progress (data )
38+ local id = (" %s.%s" ):format (data .client_id , data .result .token )
39+ M .lsp_progress [id ] = M .lsp_progress [id ] and vim .tbl_deep_extend (" force" , M .lsp_progress [id ], data .result .value )
40+ or data .result .value
41+ if M .lsp_progress [id ].kind == " end" then
42+ vim .defer_fn (function ()
43+ M .lsp_progress [id ] = nil
44+ lsp_event " Progress"
45+ end , 100 )
46+ end
47+ lsp_event " Progress"
48+ end
49+
3550--- Helper function to set up a given server with the Neovim LSP client
3651--- @param server string The name of the server to be setup
3752function M .lsp_setup (server )
@@ -233,18 +248,17 @@ function M.setup(opts)
233248 end ,
234249 })
235250
236- local progress_handler = vim .lsp .handlers [" $/progress" ]
237- vim .lsp .handlers [" $/progress" ] = function (err , res , ctx )
238- local progress , id = M .lsp_progress , (" %s.%s" ):format (ctx .client_id , res .token )
239- progress [id ] = progress [id ] and vim .tbl_deep_extend (" force" , progress [id ], res .value ) or res .value
240- if progress [id ].kind == " end" then
241- vim .defer_fn (function ()
242- progress [id ] = nil
243- lsp_event " Progress"
244- end , 100 )
251+ local ok = pcall (vim .api .nvim_create_autocmd , " LspProgress" , {
252+ group = vim .api .nvim_create_augroup (" astrolsp_progress" , { clear = true }),
253+ desc = " Collect LSP progress messages for later handling" ,
254+ callback = function (event ) M .progress (event .data ) end ,
255+ })
256+ if not ok then
257+ local progress_handler = vim .lsp .handlers [" $/progress" ]
258+ vim .lsp .handlers [" $/progress" ] = function (err , res , ctx )
259+ M .progress { client_id = ctx .client_id , result = res }
260+ progress_handler (err , res , ctx )
245261 end
246- lsp_event " Progress"
247- progress_handler (err , res , ctx )
248262 end
249263
250264 local register_capability_handler = vim .lsp .handlers [" client/registerCapability" ]
0 commit comments