summaryrefslogtreecommitdiff
path: root/lua/blink/cmp/config/completion/documentation.lua
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2025-01-19 13:52:52 +0100
committerMike Vink <mike@pionative.com>2025-01-19 13:52:52 +0100
commitb77413ff8f59f380612074f0c9bd49093d8db695 (patch)
tree32c39a811ba96ed4ab0a1c81cce9f8d518ed7e31 /lua/blink/cmp/config/completion/documentation.lua
Squashed 'mut/neovim/pack/plugins/start/blink.cmp/' content from commit 1cc3b1a
git-subtree-dir: mut/neovim/pack/plugins/start/blink.cmp git-subtree-split: 1cc3b1a908fbcfd15451c4772759549724f38524
Diffstat (limited to 'lua/blink/cmp/config/completion/documentation.lua')
-rw-r--r--lua/blink/cmp/config/completion/documentation.lua98
1 files changed, 98 insertions, 0 deletions
diff --git a/lua/blink/cmp/config/completion/documentation.lua b/lua/blink/cmp/config/completion/documentation.lua
new file mode 100644
index 0000000..71784d1
--- /dev/null
+++ b/lua/blink/cmp/config/completion/documentation.lua
@@ -0,0 +1,98 @@
+--- @class (exact) blink.cmp.CompletionDocumentationConfig
+--- @field auto_show boolean Controls whether the documentation window will automatically show when selecting a completion item
+--- @field auto_show_delay_ms number Delay before showing the documentation window
+--- @field update_delay_ms number Delay before updating the documentation window when selecting a new item, while an existing item is still visible
+--- @field treesitter_highlighting boolean Whether to use treesitter highlighting, disable if you run into performance issues
+--- @field window blink.cmp.CompletionDocumentationWindowConfig
+
+--- @class (exact) blink.cmp.CompletionDocumentationWindowConfig
+--- @field min_width number
+--- @field max_width number
+--- @field max_height number
+--- @field desired_min_width number
+--- @field desired_min_height number
+--- @field border blink.cmp.WindowBorder
+--- @field winblend number
+--- @field winhighlight string
+--- @field scrollbar boolean Note that the gutter will be disabled when border ~= 'none'
+--- @field direction_priority blink.cmp.CompletionDocumentationDirectionPriorityConfig Which directions to show the window, for each of the possible menu window directions, falling back to the next direction when there's not enough space
+
+--- @class (exact) blink.cmp.CompletionDocumentationDirectionPriorityConfig
+--- @field menu_north ("n" | "s" | "e" | "w")[]
+--- @field menu_south ("n" | "s" | "e" | "w")[]
+
+local validate = require('blink.cmp.config.utils').validate
+local documentation = {
+ --- @type blink.cmp.CompletionDocumentationConfig
+ default = {
+ auto_show = false,
+ auto_show_delay_ms = 500,
+ update_delay_ms = 50,
+ treesitter_highlighting = true,
+ window = {
+ min_width = 10,
+ max_width = 80,
+ max_height = 20,
+ desired_min_width = 50,
+ desired_min_height = 10,
+ border = 'padded',
+ winblend = 0,
+ winhighlight = 'Normal:BlinkCmpDoc,FloatBorder:BlinkCmpDocBorder,EndOfBuffer:BlinkCmpDoc',
+ scrollbar = true,
+ direction_priority = {
+ menu_north = { 'e', 'w', 'n', 's' },
+ menu_south = { 'e', 'w', 's', 'n' },
+ },
+ },
+ },
+}
+
+function documentation.validate(config)
+ validate('completion.documentation', {
+ auto_show = { config.auto_show, 'boolean' },
+ auto_show_delay_ms = { config.auto_show_delay_ms, 'number' },
+ update_delay_ms = { config.update_delay_ms, 'number' },
+ treesitter_highlighting = { config.treesitter_highlighting, 'boolean' },
+ window = { config.window, 'table' },
+ }, config)
+
+ validate('completion.documentation.window', {
+ min_width = { config.window.min_width, 'number' },
+ max_width = { config.window.max_width, 'number' },
+ max_height = { config.window.max_height, 'number' },
+ desired_min_width = { config.window.desired_min_width, 'number' },
+ desired_min_height = { config.window.desired_min_height, 'number' },
+ border = { config.window.border, { 'string', 'table' } },
+ winblend = { config.window.winblend, 'number' },
+ winhighlight = { config.window.winhighlight, 'string' },
+ scrollbar = { config.window.scrollbar, 'boolean' },
+ direction_priority = { config.window.direction_priority, 'table' },
+ }, config.window)
+
+ validate('completion.documentation.window.direction_priority', {
+ menu_north = {
+ config.window.direction_priority.menu_north,
+ function(directions)
+ if type(directions) ~= 'table' or #directions == 0 then return false end
+ for _, direction in ipairs(directions) do
+ if not vim.tbl_contains({ 'n', 's', 'e', 'w' }, direction) then return false end
+ end
+ return true
+ end,
+ 'one of: "n", "s", "e", "w"',
+ },
+ menu_south = {
+ config.window.direction_priority.menu_south,
+ function(directions)
+ if type(directions) ~= 'table' or #directions == 0 then return false end
+ for _, direction in ipairs(directions) do
+ if not vim.tbl_contains({ 'n', 's', 'e', 'w' }, direction) then return false end
+ end
+ return true
+ end,
+ 'one of: "n", "s", "e", "w"',
+ },
+ }, config.window.direction_priority)
+end
+
+return documentation