Skip to content

Commit

Permalink
feat(diag): add diagnostics_update_on_event option (#932)
Browse files Browse the repository at this point in the history
* feat(diag): add `diagnostics_update_on_event` option

* feat(diag)!: deprecate `diagnostics_update_in_insert` for nvim_lsp
  • Loading branch information
gepbird authored Jul 10, 2024
1 parent 81820ca commit aa16daf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion doc/bufferline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ The available configuration are:
truncate_names = true, -- whether or not tab names should be truncated
tab_size = 18,
diagnostics = false | "nvim_lsp" | "coc",
diagnostics_update_in_insert = false,
diagnostics_update_in_insert = false, -- only applies to coc
diagnostics_update_on_event = true, -- 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
13 changes: 13 additions & 0 deletions lua/bufferline/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ local function validate_user_options(options)
local item = deprecations[key]
if item then vim.schedule(function() vim.deprecate(item.name, item.alternative, item.version, "bufferline") end) end
end
if options.diagnostics == "nvim_lsp" and options.diagnostics_update_in_insert then
vim.schedule(
function()
vim.deprecate(
"diagnostics_update_in_insert",
"vim.diagnostic.config { update_in_insert = true }",
"4.6.3",
"bufferline"
)
end
)
end
end

---@param options bufferline.Options
Expand Down Expand Up @@ -657,6 +669,7 @@ local function get_defaults()
diagnostics = false,
diagnostics_indicator = nil,
diagnostics_update_in_insert = true,
diagnostics_update_on_event = true,
offsets = {},
groups = { items = {}, options = { toggle_hidden_on_enter = true } },
hover = { enabled = false, reveal = {}, delay = 200 },
Expand Down
4 changes: 3 additions & 1 deletion lua/bufferline/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ end
---@param opts table
function M.get(opts)
if is_disabled(opts.diagnostics) then return setmetatable({}, mt) end
if is_insert() and not opts.diagnostics_update_in_insert then return setmetatable(last_diagnostics_result, mt) end
local update_nvim = opts.diagnostics == "nvim_lsp" and vim.diagnostic.config().update_in_insert
local update_coc = opts.diagnostics == "coc" and opts.diagnostics_update_in_insert
if is_insert() and not update_nvim and not update_coc then return setmetatable(last_diagnostics_result, mt) end
local diagnostics = get_diagnostics[opts.diagnostics]()
local result = {}
for buf_num, items in pairs(diagnostics) do
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 aa16daf

Please sign in to comment.