Is it possible to refresh LSP diagnostics when opening a buffer? #310
-
Hi, I've created a new iOS project in Xcode (attached below) and changed the view reference from I know I can view build errors using the quick fix list (which is a great feature!), but I'd like them to appear in the buffer without having to make an edit. Is this possible? Notes
Sample ProjectScreen Recordingneovim-lsp.mp4 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hi, those marks are handled by the LSP. Probably, the first check is triggered on edit. Have you tried calilng |
Beta Was this translation helpful? Give feedback.
-
Thanks for your quick response! I restarted the LSP server, but it didn't help. The only noticeable effect was that the syntax highlighting briefly disappeared. Does the plugin send warnings and errors from the build log to the LSP diagnostics, or are they handled separately? My issue is that after a failed build, I use the quick fix list to open the source file, but no errors appear in the buffer. I always have to make a small edit to the file to trigger them, which gets a bit tedious over time. |
Beta Was this translation helpful? Give feedback.
-
I've discovered that reloading the buffer displays LSP diagnostics. The workaround below is a bit hacky, but it works for now. If anyone finds a better solution, please let me know! 😅 local last_buf = nil
-- Workaround to show LSP errors when opening a Swift file
vim.api.nvim_create_autocmd("BufEnter", {
pattern = "*.swift",
callback = function(ev)
-- This check prevents an infinite loop
-- Reloading the buffer causes another "BufEnter" event
if last_buf ~= ev.buf then
last_buf = ev.buf
vim.defer_fn(function()
-- This check avoids unnecessary flickering when navigating between buffers
-- Reload the buffer only when there are build errors
local quickfix_list = vim.fn.getqflist()
if #quickfix_list > 0 then
vim.cmd("e")
end
end, 250)
end
end,
}) |
Beta Was this translation helpful? Give feedback.
I've discovered that reloading the buffer displays LSP diagnostics. The workaround below is a bit hacky, but it works for now. If anyone finds a better solution, please let me know! 😅