This commit is contained in:
hrsh7th 2022-08-15 02:43:20 +09:00
parent b1ebdb0a17
commit 5fdd71261f
3 changed files with 76 additions and 4 deletions

View file

@ -71,10 +71,8 @@ lua <<EOF
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
view = require('cmp-default-view')({
}),
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),

View file

@ -0,0 +1,45 @@
---@class cmp-default-menu-view.Option
---@field public border string|string[]
---@field public highlight string|table<string,string>
local View = {}
View.__index = View
---@param option cmp-default-menu-view.Option
function View.new(option)
local self = setmetatable({}, View)
self.option = option
return self
end
---@param context cmp.ViewContext
function View:show(context)
end
---@param context cmp.ViewContext
function View:hide(context)
end
---@param context cmp.ViewContext
function View:select(context)
end
---@param option cmp-default-menu-view.Option
return function(option)
local view = View.new(option)
---@param context cmp.ViewContext
return function(context)
context:on_show(function()
view:show(context)
end)
context:on_hide(function()
view:hide(context)
end)
context:on_select(function()
view:select(context)
end)
end
end

29
lua/cmp/view_context.lua Normal file
View file

@ -0,0 +1,29 @@
local event = require "cmp.utils.event"
---@class cmp.ViewContext
---@field public event cmp.Event
local ViewContext = {}
function ViewContext.new()
local self = setmetatable({}, { __index = ViewContext })
self.event = event.new()
return self
end
---@param callback fun(context: cmp.ViewContext)
function ViewContext:on_show(callback)
self.event:on('show', callback)
end
---@param callback fun(context: cmp.ViewContext)
function ViewContext:on_hide(callback)
self.event:on('hide', callback)
end
---@param callback fun(context: cmp.ViewContext)
function ViewContext:on_select(callback)
self.event:on('select', callback)
end
return ViewContext