This commit is contained in:
hrsh7th
2022-01-25 10:06:36 +09:00
parent 27123b1297
commit 2d67b6dd76
3 changed files with 76 additions and 77 deletions

View File

@@ -260,57 +260,45 @@ core.complete = function(self, ctx)
end
---Update completion menu
core.filter = async.throttle(
setmetatable({
ctx = nil,
}, {
__call = function(this, self)
self.filter.timeout = self.view:visible() and THROTTLE_TIME or 0
core.filter = async.throttle(function(self)
self.filter.timeout = self.view:visible() and THROTTLE_TIME or 0
-- Check context changed.
local ctx = self:get_context()
if this.ctx and not this.ctx:changed(ctx) then
return
end
this.ctx = ctx
-- Check invalid condition.
local ignore = false
ignore = ignore or not api.is_suitable_mode()
if ignore then
return
end
-- Check fetching sources.
local sources = {}
for _, s in ipairs(self:get_sources({ source.SourceStatus.FETCHING, source.SourceStatus.COMPLETED })) do
if not s.incomplete and SOURCE_TIMEOUT > s:get_fetching_time() then
-- Reserve filter call for timeout.
self.filter.timeout = SOURCE_TIMEOUT - s:get_fetching_time()
self:filter()
break
end
table.insert(sources, s)
end
-- Display completion results.
self.view:open(ctx, sources)
-- Check onetime config.
if #self:get_sources(function(s)
if s.status == source.SourceStatus.FETCHING then
return true
elseif #s:get_entries(ctx) > 0 then
return true
end
return false
end) == 0 then
config.set_onetime({})
end
-- Check invalid condition.
local ignore = false
ignore = ignore or not api.is_suitable_mode()
if ignore then
return
end
}),
THROTTLE_TIME
)
-- Check fetching sources.
local sources = {}
for _, s in ipairs(self:get_sources({ source.SourceStatus.FETCHING, source.SourceStatus.COMPLETED })) do
if not s.incomplete and SOURCE_TIMEOUT > s:get_fetching_time() then
-- Reserve filter call for timeout.
self.filter.timeout = SOURCE_TIMEOUT - s:get_fetching_time()
self:filter()
break
end
table.insert(sources, s)
end
local ctx = self:get_context()
-- Display completion results.
self.view:open(ctx, sources)
-- Check onetime config.
if #self:get_sources(function(s)
if s.status == source.SourceStatus.FETCHING then
return true
elseif #s:get_entries(ctx) > 0 then
return true
end
return false
end) == 0 then
config.set_onetime({})
end
end, THROTTLE_TIME)
---Confirm completion.
---@param e cmp.Entry