Refresh generated neovim config
This commit is contained in:
@ -8,63 +8,89 @@ local Error = {_id = errorId}
|
||||
Error.__index = Error
|
||||
|
||||
local function dump(o, limit)
|
||||
local s
|
||||
if type(o) ~= 'table' then
|
||||
s = tostring(o)
|
||||
else
|
||||
local meta = getmetatable(o)
|
||||
if meta and meta.__tostring then
|
||||
s = tostring(o)
|
||||
else
|
||||
if limit > 0 then
|
||||
local fmt = '%s [%s] = %s,'
|
||||
s = '{'
|
||||
for k, v in pairs(o) do
|
||||
if type(k) ~= 'number' then
|
||||
k = '"' .. k .. '"'
|
||||
end
|
||||
s = fmt:format(s, k, dump(v, limit - 1))
|
||||
end
|
||||
s = s:sub(1, #s - 1) .. ' }'
|
||||
else
|
||||
s = '{...}'
|
||||
end
|
||||
end
|
||||
local typ = type(o)
|
||||
if typ == 'string' then
|
||||
return o
|
||||
elseif typ ~= 'table' then
|
||||
return tostring(o)
|
||||
end
|
||||
local meta = getmetatable(o)
|
||||
if meta and meta.__tostring then
|
||||
return tostring(o)
|
||||
end
|
||||
if limit > 0 then
|
||||
local fmt = '%s [%s] = %s,'
|
||||
local s = '{'
|
||||
for k, v in pairs(o) do
|
||||
if type(k) ~= 'number' then
|
||||
k = '"' .. k .. '"'
|
||||
end
|
||||
s = fmt:format(s, k, dump(v, limit - 1))
|
||||
end
|
||||
return #s == 1 and '{}' or s:sub(1, #s - 1) .. ' }'
|
||||
else
|
||||
return '{...}'
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
function Error.isInstance(o)
|
||||
return type(o) == 'table' and o._id == errorId
|
||||
end
|
||||
|
||||
---@param thread? thread
|
||||
---@param level number
|
||||
---@param skipShortSrc? string
|
||||
---@return string?
|
||||
function Error.format(thread, level, skipShortSrc)
|
||||
local res
|
||||
local dInfo = thread and debug.getinfo(thread, level, 'nSl') or debug.getinfo(level, 'nSl')
|
||||
if dInfo then
|
||||
local name, shortSrc, currentline = dInfo.name, dInfo.short_src, dInfo.currentline
|
||||
if skipShortSrc == shortSrc then
|
||||
return
|
||||
end
|
||||
local detail
|
||||
if not name or name == '' then
|
||||
detail = ('in function <Anonymous:%d>'):format(dInfo.linedefined)
|
||||
else
|
||||
detail = ([[in function '%s']]):format(name)
|
||||
end
|
||||
res = (' %s:%d: %s'):format(shortSrc, currentline, detail)
|
||||
local what = _G._VERSION:sub(-3) == '5.1' and 'Snl' or 'Slnt'
|
||||
|
||||
local function outputLevelInfo(dInfo)
|
||||
local seg = {('\t%s:'):format(dInfo.short_src)}
|
||||
if dInfo.currentline > 0 then
|
||||
table.insert(seg, ('%d:'):format(dInfo.currentline))
|
||||
end
|
||||
return res
|
||||
-- TODO
|
||||
-- lua 5.3 and 5.4 will look up global function and module function before checking 'namewhat'.
|
||||
-- And insert "in namewhat name" if not found
|
||||
if dInfo.namewhat ~= '' then
|
||||
table.insert(seg, (" in function '%s'"):format(dInfo.name))
|
||||
else
|
||||
if dInfo.what == 'm' then
|
||||
table.insert(seg, ' in main chunk')
|
||||
elseif dInfo.what ~= 'C' then
|
||||
table.insert(seg, (' in function <%s:%d>'):format(dInfo.short_src, dInfo.linedefined))
|
||||
else
|
||||
table.insert(seg, '?')
|
||||
end
|
||||
end
|
||||
if dInfo.istailcall then
|
||||
table.insert(seg, '\n\t(...tail calls...)')
|
||||
end
|
||||
return table.concat(seg, '')
|
||||
end
|
||||
|
||||
---@param startLevel? number
|
||||
---@param skipShortSrc? string
|
||||
---@param doPop? boolean
|
||||
---@return PromiseAsyncError
|
||||
function Error:buildStack(startLevel, skipShortSrc, doPop)
|
||||
local level = startLevel or 1
|
||||
local value
|
||||
local thread = coroutine.running()
|
||||
while true do
|
||||
local dInfo = thread and debug.getinfo(thread, level, what) or debug.getinfo(level, what)
|
||||
if not dInfo or skipShortSrc == dInfo.short_src then
|
||||
break
|
||||
end
|
||||
value = outputLevelInfo(dInfo)
|
||||
level = level + 1
|
||||
self:push(value)
|
||||
end
|
||||
if doPop then
|
||||
self:pop()
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
---@param err any
|
||||
---@return PromiseAsyncError
|
||||
function Error.new(err)
|
||||
local o = setmetatable({}, Error)
|
||||
function Error:new(err)
|
||||
local o = setmetatable({}, self)
|
||||
o.err = err
|
||||
o.queue = {}
|
||||
o.index = 0
|
||||
@ -107,6 +133,11 @@ function Error:push(value)
|
||||
return #self.queue
|
||||
end
|
||||
|
||||
---@return string
|
||||
function Error:pop()
|
||||
return table.remove(self.queue)
|
||||
end
|
||||
|
||||
---@return any
|
||||
function Error:peek()
|
||||
return self.err
|
||||
|
||||
@ -37,6 +37,8 @@ local function runTick()
|
||||
else
|
||||
EventLoop.tickStarted = false
|
||||
end
|
||||
-- luv loop has invoked close method if the timer has finished
|
||||
-- EventLoop.tick:close()
|
||||
end
|
||||
|
||||
function EventLoop.nextTick(callback)
|
||||
@ -53,11 +55,9 @@ local function runIdle()
|
||||
for _, cb in ipairs(callbacks) do
|
||||
EventLoop.callWrapper(cb)
|
||||
end
|
||||
if #EventLoop.idleCallbacks > 0 then
|
||||
EventLoop.idle:start(runIdle)
|
||||
else
|
||||
EventLoop.idle:stop()
|
||||
if #EventLoop.idleCallbacks == 0 then
|
||||
EventLoop.idleStarted = false
|
||||
EventLoop.idle:stop()
|
||||
end
|
||||
end
|
||||
|
||||
@ -73,13 +73,8 @@ end
|
||||
if vim and type(vim.schedule) == 'function' then
|
||||
EventLoop.callWrapper = vim.schedule
|
||||
else
|
||||
function EventLoop.callWrapper(fn)
|
||||
local ok, res = pcall(fn)
|
||||
if not ok then
|
||||
-- luv can't handle object with __tostring filed
|
||||
error(tostring(res))
|
||||
end
|
||||
end
|
||||
-- https://github.com/luvit/luv/pull/665 can throw the non-string error since 1.46 version
|
||||
function EventLoop.callWrapper(fn) fn() end
|
||||
end
|
||||
|
||||
return EventLoop
|
||||
|
||||
@ -87,22 +87,6 @@ local function getThenable(o, typ)
|
||||
return thenCall
|
||||
end
|
||||
|
||||
---@param err any
|
||||
---@return PromiseAsyncError
|
||||
local function buildError(err)
|
||||
local o = errFactory.new(err)
|
||||
local level = 4
|
||||
local value
|
||||
local thread = coroutine.running()
|
||||
repeat
|
||||
value = errFactory.format(thread, level, shortSrc)
|
||||
level = level + 1
|
||||
o:push(value)
|
||||
until not value
|
||||
table.remove(o.queue)
|
||||
return o
|
||||
end
|
||||
|
||||
local resolvePromise, rejectPromise
|
||||
|
||||
---@param promise Promise
|
||||
@ -139,7 +123,10 @@ local function handleQueue(promise)
|
||||
return func(result)
|
||||
end, function(errmsg)
|
||||
if type(errmsg) == 'string' then
|
||||
newPromise.err = buildError(errmsg)
|
||||
-- pop xpcall stack
|
||||
newPromise.err = errFactory:new(errmsg)
|
||||
:buildStack(3, shortSrc, true)
|
||||
return tostring(newPromise.err)
|
||||
end
|
||||
return errmsg
|
||||
end)
|
||||
@ -194,7 +181,10 @@ local function wrapExecutor(promise, executor, self)
|
||||
end
|
||||
end, function(errmsg)
|
||||
if type(errmsg) == 'string' then
|
||||
promise.err = buildError(errmsg)
|
||||
-- pop xpcall stack
|
||||
promise.err = errFactory:new(errmsg)
|
||||
:buildStack(3, shortSrc, true)
|
||||
return tostring(promise.err)
|
||||
end
|
||||
return errmsg
|
||||
end)
|
||||
@ -212,7 +202,7 @@ local function handleRejection(promise)
|
||||
promise.needHandleRejection = nil
|
||||
local err = promise.err
|
||||
if not err then
|
||||
err = errFactory.new(promise.result)
|
||||
err = errFactory:new(promise.result)
|
||||
end
|
||||
err:unshift('UnhandledPromiseRejection with the reason:')
|
||||
error(err)
|
||||
|
||||
Reference in New Issue
Block a user