应该是近期,refactoring.nvim更改使用了async.nvim作为它使用的async实现 而其他的比如nvim-ufo使用了promise-async作为async的实现

算是比较典型的依赖冲突,解决方案也就是提前拦截require了(比较本的方法,实 际上如果作为插件的实现不应该这么做,不过这里是要打个猴子补丁)

大概就是这样

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local data = vim.fn.stdpath('data')
local paths = {
async_nvim = data .. '/lazy/async.nvim/lua/async.lua',
promise = data .. '/lazy/promise-async/lua/async.lua',
}
local loaded = {}
local function load(kind)
if not loaded[kind] then loaded[kind] = dofile(paths[kind]) end
return loaded[kind]
end

local orig_require = _G.require
_G.require = function(modname, ...)
if modname ~= 'async' then return orig_require(modname, ...) end

for lvl = 2, 16 do
local info = debug.getinfo(lvl, 'S')
if not info then break end
local src = info.source or ''
if src:find('refactoring', 1, true) then return load('async_nvim') end
if src:find('nvim-ufo', 1, true) then return load('promise') end

if src:find('fundo', 1, true) then return load('promise') end
if src:find('promise-async', 1, true) then return load('promise') end
end
return load('async_nvim')
end

保存后确保在lazy或者其他插件管理器加载之前加载这个