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", + ] +} 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..8de5a078 100644 --- a/lua/diffview/utils.lua +++ b/lua/diffview/utils.lua @@ -1346,4 +1346,11 @@ end M.path_sep = path_sep +--- @param t table +--- @return table t +function M.add_reverse_lookup(t) + for k, v in pairs(t) do t[v] = k end + return t +end + return M