Skip to content

Commit 642dfd7

Browse files
committed
docs: add type hints to picker module
1 parent 1846130 commit 642dfd7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lua/utils/picker.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
local config = require('utils.config')
22
local picker_provider = config.config.picker_provider
33

4+
---@class Utils.Picker.CommonOptions
5+
---@field cwd? string -- Current working directory
6+
---@field title? string -- Window title
7+
8+
---@class Utils.Picker.SelectFileOptions
9+
---@field items string[] -- List of file paths to select from
10+
---@field title string -- Window title
11+
12+
---@class Utils.Picker.CustomPickerOptions
13+
---@field items table -- List of items to display
14+
---@field title string -- Window title
15+
---@field entry_maker fun(item:any):table -- Converts raw items to picker entries
16+
---@field preview_generator fun(item:any):string -- Generates preview content as string
17+
---@field preview_ft? string -- File type for preview content (defaults to 'markdown')
18+
---@field selection_handler fun(bufnr:number|nil, selection:table) -- Handler for selection
19+
420
---@class Utils.Picker
521
local M = {}
622

@@ -195,6 +211,8 @@ local function get_picker_command(command, opts)
195211
return picker_commands[command][picker_provider]
196212
end
197213

214+
---Open file picker, using git_files if in git repo, otherwise find_files
215+
---@param opts Utils.Picker.CommonOptions
198216
M.files = function(opts)
199217
local is_git_repo =
200218
vim.fn.system('cd ' .. opts.cwd .. ' && git rev-parse --is-inside-work-tree 2>/dev/null'):match('true')
@@ -205,20 +223,26 @@ M.files = function(opts)
205223
end)
206224
end
207225

226+
---Open live grep search
227+
---@param opts Utils.Picker.CommonOptions
208228
M.live_grep = function(opts)
209229
vim.schedule(function()
210230
local picker_cmd = get_picker_command('live_grep', opts)
211231
picker_cmd()
212232
end)
213233
end
214234

235+
---Open a picker to select from a list of files
236+
---@param opts Utils.Picker.SelectFileOptions
215237
M.select_file = function(opts)
216238
vim.schedule(function()
217239
local picker_cmd = get_picker_command('select_file', opts)
218240
picker_cmd()
219241
end)
220242
end
221243

244+
---Open a custom picker with a custom preview generator and entry maker
245+
---@param opts Utils.Picker.CustomPickerOptions
222246
M.custom = function(opts)
223247
vim.schedule(function()
224248
local picker_cmd = get_picker_command('custom', opts)

0 commit comments

Comments
 (0)