Skip to content

Is it possible to refresh LSP diagnostics when opening a buffer? #310

Answered by FelixLisczyk
FelixLisczyk asked this question in Q&A
Discussion options

You must be logged in to vote

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
        

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@wojciech-kulik
Comment options

Comment options

You must be logged in to vote
1 reply
@wojciech-kulik
Comment options

Answer selected by FelixLisczyk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants