forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanel.lua
More file actions
56 lines (51 loc) · 2.17 KB
/
panel.lua
File metadata and controls
56 lines (51 loc) · 2.17 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---@class (exact) PanelConfig
---@field enabled boolean Whether to enable the panel
---@field auto_refresh boolean Whether to automatically refresh the panel
---@field keymap PanelKeymapConfig Keymap for the panel
---@field layout PanelLayoutConfig Layout of the panel
---@class (exact) PanelKeymapConfig
---@field jump_prev string|false Keymap for jumping to the previous suggestion
---@field jump_next string|false Keymap for jumping to the next suggestion
---@field accept string|false Keymap for accepting the suggestion
---@field refresh string|false Keymap for refreshing the suggestion
---@field open string|false Keymap for opening the suggestion
---@class (exact) PanelLayoutConfig
---@field position string<'left'|'right'|'top'|'bottom'> Position of the panel
---@field ratio number Ratio of the panel size, between 0 and 1
local panel = {
---@type PanelConfig
default = {
enabled = true,
auto_refresh = false,
keymap = {
jump_prev = "[[",
jump_next = "]]",
accept = "<CR>",
refresh = "gr",
open = "<M-CR>",
},
layout = {
position = "bottom",
ratio = 0.4,
},
},
}
---@param config PanelConfig
function panel.validate(config)
vim.validate("enabled", config.enabled, "boolean")
vim.validate("auto_refresh", config.auto_refresh, "boolean")
vim.validate("keymap", config.keymap, "table")
vim.validate("layout", config.layout, "table")
vim.validate("keymap.jump_prev", config.keymap.jump_prev, { "string", "boolean" })
vim.validate("keymap.jump_next", config.keymap.jump_next, { "string", "boolean" })
vim.validate("keymap.accept", config.keymap.accept, { "string", "boolean" })
vim.validate("keymap.refresh", config.keymap.refresh, { "string", "boolean" })
vim.validate("keymap.open", config.keymap.open, { "string", "boolean" })
vim.validate("layout.position", config.layout.position, function(value)
return value == "left" or value == "right" or value == "top" or value == "bottom"
end, false, "left, right, top or bottom")
vim.validate("layout.ratio", config.layout.ratio, function(value)
return type(value) == "number" and value >= 0 and value <= 1
end, false, "number between 0 and 1")
end
return panel