From 8fa373ca266265f0e17887f1ceb84c7eb55b7c5e Mon Sep 17 00:00:00 2001 From: erw7 Date: Tue, 15 Sep 2020 00:41:25 +0900 Subject: [PATCH] Change call to refresh_diagnostics() to be delayed Changing the location list from autocmd can cause problems. As a workaround, delay the call to refresh_diagnostics(). --- lua/diagnostic.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/diagnostic.lua b/lua/diagnostic.lua index 2ff67af..397f36b 100644 --- a/lua/diagnostic.lua +++ b/lua/diagnostic.lua @@ -98,6 +98,12 @@ function M.refresh_diagnostics() M.publish_diagnostics(bufnr) end +function M.on_BufEnter() + vim.schedule(function() + M.refresh_diagnostics() + end) +end + function M.on_InsertLeave() M.refresh_diagnostics() end @@ -115,7 +121,7 @@ M.on_attach = function(_, _) M.modifyCallback() vim.api.nvim_command [[augroup DiagnosticRefresh]] vim.api.nvim_command("autocmd! * ") - vim.api.nvim_command [[autocmd BufEnter,BufWinEnter,TabEnter lua require'diagnostic'.refresh_diagnostics()]] + vim.api.nvim_command [[autocmd BufEnter,BufWinEnter,TabEnter lua require'diagnostic'.on_BufEnter()]] vim.api.nvim_command [[augroup end]] if vim.api.nvim_get_var('diagnostic_insert_delay') == 1 then