Skip to content

Commit

Permalink
fix: reimplement the deprecated function tbl_add_reverse_lookup (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
cttttt committed May 19, 2024
1 parent 2cd3984 commit 9ae49d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lua/bufferline/diagnostics.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
local lazy = require("bufferline.lazy")
local config = lazy.require("bufferline.config") ---@module "bufferline.config"
local ui = lazy.require("bufferline.ui") ---@module "bufferline.ui"
local utils = lazy.require("bufferline.utils") ---@module "bufferline.utils"

local M = {}

local fn = vim.fn
local fmt = string.format

local severity_name = vim.tbl_add_reverse_lookup({
local severity_name = utils.tbl_add_reverse_lookup({
[1] = "error",
[2] = "warning",
[3] = "info",
Expand Down
16 changes: 16 additions & 0 deletions lua/bufferline/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ function M.tbl_reverse_lookup(tbl)
return ret
end

--- creates a table containing the forward and reversed mapping from the provided
--- table.
--- similar to the now deprecated vim.tbl_add_reverse_lookup
--- @generic K,V
--- @param tbl table<K,V>
--- @return table<V,K>
function M.tbl_add_reverse_lookup(tbl)
local ret = {}
for k, v in pairs(tbl) do
ret[k] = v
ret[v] = k
end

return ret
end

M.path_sep = vim.fn.has("win32") == 1 and "\\" or "/"

-- The provided api nvim_is_buf_loaded filters out all hidden buffers
Expand Down

0 comments on commit 9ae49d7

Please # to comment.