Skip to content

Commit

Permalink
feat(diag): add diagnostics_update_on_event option
Browse files Browse the repository at this point in the history
  • Loading branch information
gepbird committed Jun 25, 2024
1 parent 81820ca commit e33329e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/bufferline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ The available configuration are:
tab_size = 18,
diagnostics = false | "nvim_lsp" | "coc",
diagnostics_update_in_insert = false,
diagnostics_update_on_event = false, -- use nvim's diagnostic handler
-- The diagnostics indicator can be set to nil to keep the buffer name highlight but delete the highlighting
diagnostics_indicator = function(count, level, diagnostics_dict, context)
return "("..count..")"
Expand Down
10 changes: 10 additions & 0 deletions lua/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ local function setup_commands()
})
end

local function setup_diagnostic_handler(preferences)
if preferences.options.diagnostics == "nvim_lsp" and preferences.options.diagnostics_update_on_event then
vim.diagnostic.handlers["bufferline"] = {
show = function() ui.refresh() end,
hide = function() ui.refresh() end,
}
end
end

---@param conf bufferline.UserConfig?
function M.setup(conf)
conf = conf or {}
Expand All @@ -192,6 +201,7 @@ function M.setup(conf)
hover.setup(preferences)
setup_commands()
setup_autocommands(preferences)
setup_diagnostic_handler(preferences)
vim.o.tabline = "%!v:lua.nvim_bufferline()"
toggle_bufferline()
end
Expand Down
1 change: 1 addition & 0 deletions lua/bufferline/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ local function get_defaults()
diagnostics = false,
diagnostics_indicator = nil,
diagnostics_update_in_insert = true,
diagnostics_update_on_event = false,
offsets = {},
groups = { items = {}, options = { toggle_hidden_on_enter = true } },
hover = { enabled = false, reveal = {}, delay = 200 },
Expand Down
1 change: 1 addition & 0 deletions lua/bufferline/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
---@field public diagnostics? boolean | 'nvim_lsp' | 'coc'
---@field public diagnostics_indicator? bufferline.DiagnosticIndicator
---@field public diagnostics_update_in_insert? boolean
---@field public diagnostics_update_on_event? boolean
---@field public offsets? table[]
---@field public groups? bufferline.GroupOpts
---@field public themable? boolean
Expand Down

0 comments on commit e33329e

Please sign in to comment.