From 9ae49d71c84b42b91795f7b7cead223c6346e774 Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Sun, 19 May 2024 06:33:15 -0400 Subject: [PATCH] fix: reimplement the deprecated function tbl_add_reverse_lookup (#904) --- lua/bufferline/diagnostics.lua | 3 ++- lua/bufferline/utils/init.lua | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lua/bufferline/diagnostics.lua b/lua/bufferline/diagnostics.lua index a1db846e..ac7218bb 100644 --- a/lua/bufferline/diagnostics.lua +++ b/lua/bufferline/diagnostics.lua @@ -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", diff --git a/lua/bufferline/utils/init.lua b/lua/bufferline/utils/init.lua index fe19eeb6..a87b7207 100644 --- a/lua/bufferline/utils/init.lua +++ b/lua/bufferline/utils/init.lua @@ -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 +--- @return table +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