Fix multiple setup.buffer

This commit is contained in:
hrsh7th
2021-08-29 22:23:54 +09:00
parent b9ef85d483
commit 25a4d9c0be
2 changed files with 12 additions and 3 deletions

View File

@@ -26,9 +26,9 @@ end
---@param c cmp.ConfigSchema ---@param c cmp.ConfigSchema
---@param bufnr number|nil ---@param bufnr number|nil
config.set_buffer = function(c, bufnr) config.set_buffer = function(c, bufnr)
local revision = (config.buffers[bufnr] or {}).revision or 1
config.buffers[bufnr] = c config.buffers[bufnr] = c
config.buffers[bufnr].revision = config.buffers[bufnr].revision or 1 config.buffers[bufnr].revision = revision + 1
config.buffers[bufnr].revision = config.buffers[bufnr].revision + 1
end end
---@return cmp.ConfigSchema ---@return cmp.ConfigSchema

View File

@@ -48,10 +48,17 @@ end
core.get_context = function(option) core.get_context = function(option)
local prev = core.context:clone() local prev = core.context:clone()
prev.prev_context = nil prev.prev_context = nil
core.context = context.new(prev, option) local ctx = context.new(prev, option)
core.set_context(ctx)
return core.context return core.context
end end
---Set new context
---@param ctx cmp.Context
core.set_context = function(ctx)
core.context = ctx
end
---Get sources that sorted by priority ---Get sources that sorted by priority
---@param statuses cmp.SourceStatus[] ---@param statuses cmp.SourceStatus[]
---@return cmp.Source[] ---@return cmp.Source[]
@@ -149,6 +156,8 @@ end
---Invoke completion ---Invoke completion
---@param ctx cmp.Context ---@param ctx cmp.Context
core.complete = function(ctx) core.complete = function(ctx)
core.set_context(ctx)
local callback = function() local callback = function()
local new = context.new(ctx) local new = context.new(ctx)
if new:changed(new.prev_context) then if new:changed(new.prev_context) then