summaryrefslogtreecommitdiff
path: root/lua/lvim/utils/reload.lua
diff options
context:
space:
mode:
authorkylo252 <[email protected]>2022-10-04 19:23:52 +0200
committerGitHub <[email protected]>2022-10-04 13:23:52 -0400
commite5bcf01c759e7c833d8a5f1fcf665b6ea32a7c16 (patch)
tree51b68c8face9faa2a41fcc8103b6296213557d4b /lua/lvim/utils/reload.lua
parent560ee4d7cf4038a22a5556d79ad92cd226a792dc (diff)
refactor: more deliberate reload (#3133)
Diffstat (limited to 'lua/lvim/utils/reload.lua')
-rw-r--r--lua/lvim/utils/reload.lua80
1 files changed, 0 insertions, 80 deletions
diff --git a/lua/lvim/utils/reload.lua b/lua/lvim/utils/reload.lua
deleted file mode 100644
index 46392349..00000000
--- a/lua/lvim/utils/reload.lua
+++ /dev/null
@@ -1,80 +0,0 @@
-local M = {}
-
--- revisit this
--- function prequire(package)
--- local status, lib = pcall(require, package)
--- if status then
--- return lib
--- else
--- vim.notify("Failed to require '" .. package .. "' from " .. debug.getinfo(2).source)
--- return nil
--- end
--- end
-
-local function _assign(old, new, k)
- local otype = type(old[k])
- local ntype = type(new[k])
- -- print("hi")
- if (otype == "thread" or otype == "userdata") or (ntype == "thread" or ntype == "userdata") then
- vim.notify(string.format("warning: old or new attr %s type be thread or userdata", k))
- end
- old[k] = new[k]
-end
-
-local function _replace(old, new, repeat_tbl)
- if repeat_tbl[old] then
- return
- end
- repeat_tbl[old] = true
-
- local dellist = {}
- for k, _ in pairs(old) do
- if not new[k] then
- table.insert(dellist, k)
- end
- end
- for _, v in ipairs(dellist) do
- old[v] = nil
- end
-
- for k, _ in pairs(new) do
- if not old[k] then
- old[k] = new[k]
- else
- if type(old[k]) ~= type(new[k]) then
- vim.notify(string.format("warning: attr %s old type no equal new type!!!", k))
- _assign(old, new, k)
- else
- if type(old[k]) == "table" then
- _replace(old[k], new[k], repeat_tbl)
- else
- _assign(old, new, k)
- end
- end
- end
- end
-end
-
-M.reload = function(mod)
- if not package.loaded[mod] then
- local m = require(mod)
- return m
- end
- -- vim.notify "begin reload!!!"
-
- local old = package.loaded[mod]
- package.loaded[mod] = nil
- local new = require(mod)
-
- if type(old) == "table" and type(new) == "table" then
- -- vim.notify "pick object in new module to old module!!!"
- local repeat_tbl = {}
- _replace(old, new, repeat_tbl)
- end
-
- package.loaded[mod] = old
- -- vim.notify "finish reload!!!"
- return old
-end
-
-return M