From 0f6479ded04fe1b9372c969bfdbb3071190a1137 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 17 May 2024 09:20:19 +0100 Subject: [PATCH 1/3] fix: remove deprecated use of vim.tbl_add_reverse_lookup --- lua/diffview/hl.lua | 6 +++--- lua/diffview/lib.lua | 2 +- lua/diffview/oop.lua | 5 ++++- lua/diffview/utils.lua | 10 ++++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lua/diffview/hl.lua b/lua/diffview/hl.lua index 0c5d5b02..693dd358 100644 --- a/lua/diffview/hl.lua +++ b/lua/diffview/hl.lua @@ -114,8 +114,8 @@ if HAS_NVIM_0_8 then } end -vim.tbl_add_reverse_lookup(M.HlAttribute) -vim.tbl_add_reverse_lookup(style_attrs) +utils.add_reverse_lookup(M.HlAttribute) +utils.add_reverse_lookup(style_attrs) local hlattr = M.HlAttribute ---@param name string Syntax group name. @@ -242,7 +242,7 @@ function M.hi_spec_to_def_map(spec) end if spec.style then - local spec_attrs = vim.tbl_add_reverse_lookup(vim.split(spec.style, ",")) + local spec_attrs = utils.add_reverse_lookup(vim.split(spec.style, ",")) for _, attr in ipairs(style_attrs) do res[attr] = spec_attrs[attr] ~= nil diff --git a/lua/diffview/lib.lua b/lua/diffview/lib.lua index 6291f9b5..fa47b3be 100644 --- a/lua/diffview/lib.lua +++ b/lua/diffview/lib.lua @@ -199,7 +199,7 @@ end ---@return boolean function M.is_buf_in_use(bufnr, ignore) local ignore_map = ignore and utils.vec_slice(ignore) or {} - vim.tbl_add_reverse_lookup(ignore_map) + utils.add_reverse_lookup(ignore_map) for _, view in ipairs(M.views) do if view:instanceof(StandardView.__get()) then diff --git a/lua/diffview/oop.lua b/lua/diffview/oop.lua index ab81bf42..725b5ae0 100644 --- a/lua/diffview/oop.lua +++ b/lua/diffview/oop.lua @@ -1,3 +1,6 @@ +local lazy = require("diffview.lazy") +local utils = lazy.require("diffview.utils") ---@module "diffview.utils" + local fmt = string.format local M = {} @@ -10,7 +13,7 @@ end ---@param t T ---@return T function M.enum(t) - vim.tbl_add_reverse_lookup(t) + utils.add_reverse_lookup(t) return t end diff --git a/lua/diffview/utils.lua b/lua/diffview/utils.lua index fe7a29bc..ab3b48e0 100644 --- a/lua/diffview/utils.lua +++ b/lua/diffview/utils.lua @@ -1346,4 +1346,14 @@ end M.path_sep = path_sep +--- @param t table +--- @return table t +function M.add_reverse_lookup(t) + local keys = vim.tbl_keys(t) + for _, k in ipairs(keys) do + t[t[k]] = k + end + return t +end + return M From 1c86219ffa1ff5f620df00f9328dce6c17505f36 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 17 May 2024 09:22:49 +0100 Subject: [PATCH 2/3] fix: add VIMRUNTIME to .luarc.json --- .luarc.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.luarc.json b/.luarc.json index 5021b9ca..86b6773b 100644 --- a/.luarc.json +++ b/.luarc.json @@ -5,5 +5,8 @@ "cast-type-mismatch", "missing-fields" ], - "workspace.checkThirdParty": false -} \ No newline at end of file + "workspace.checkThirdParty": false, + "workspace.library": [ + "$VIMRUNTIME", + ] +} From 05c14991fc0c723ad845bd135379c4c78a63946f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20T=2E=20Str=C3=B8m?= Date: Sat, 18 May 2024 13:20:12 +0200 Subject: [PATCH 3/3] simplify --- lua/diffview/utils.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lua/diffview/utils.lua b/lua/diffview/utils.lua index ab3b48e0..8de5a078 100644 --- a/lua/diffview/utils.lua +++ b/lua/diffview/utils.lua @@ -1349,10 +1349,7 @@ M.path_sep = path_sep --- @param t table --- @return table t function M.add_reverse_lookup(t) - local keys = vim.tbl_keys(t) - for _, k in ipairs(keys) do - t[t[k]] = k - end + for k, v in pairs(t) do t[v] = k end return t end