minimal extui fuzzy finder for neovim

fix: types and class initialisation

+16 -19
+13 -18
lua/artio/picker.lua
··· 1 1 local View = require("artio.view") 2 2 3 - ---@alias artio.Picker.item { id: integer, v: string, text: string, icon?: string, icon_hl?: string, hls?: artio.Picker.hl[] } 3 + ---@alias artio.Picker.item { id: integer, v: any, text: string, icon?: string, icon_hl?: string, hls?: artio.Picker.hl[] } 4 4 ---@alias artio.Picker.match [integer, integer[], integer] [item, pos[], score] 5 5 ---@alias artio.Picker.sorter fun(lst: artio.Picker.item[], input: string): artio.Picker.match[] 6 6 ---@alias artio.Picker.hl [[integer, integer], string] 7 7 8 - ---@class artio.Picker.proto<T> 9 - ---@field items? artio.Picker.item[] 10 - ---@field fn? artio.Picker.sorter 11 - ---@field on_close? fun(text: string, idx: integer) 12 - ---@field format_item? fun(item: string): string 13 - ---@field preview_item? fun(item: string): integer, fun(win: integer) 8 + ---@class artio.Picker.config 9 + ---@field items artio.Picker.item[] 10 + ---@field fn artio.Picker.sorter 11 + ---@field on_close fun(text: string, idx: integer) 12 + ---@field format_item? fun(item: any): string 13 + ---@field preview_item? fun(item: any): integer, fun(win: integer) 14 14 ---@field get_icon? fun(item: artio.Picker.item): string, string 15 15 ---@field hl_item? fun(item: artio.Picker.item): artio.Picker.hl[] 16 16 ---@field opts? artio.config.opts ··· 19 19 ---@field defaulttext? string 20 20 ---@field prompttext? string 21 21 22 - ---@class artio.Picker : artio.Picker.proto 22 + ---@class artio.Picker : artio.Picker.config 23 23 ---@field idx integer 1-indexed 24 24 ---@field matches artio.Picker.match[] 25 25 local Picker = {} 26 26 Picker.__index = Picker 27 27 28 - ---@param props artio.Picker.proto 28 + ---@param props artio.Picker.config 29 29 function Picker:new(props) 30 - vim.validate("fn", props.fn, "function") 31 - vim.validate("on_close", props.on_close, "function") 30 + vim.validate("Picker.items", props.items, "table") 31 + vim.validate("Picker:fn", props.fn, "function") 32 + vim.validate("Picker:on_close", props.on_close, "function") 32 33 33 34 local t = vim.tbl_deep_extend("force", { 34 35 closed = false, ··· 62 63 end 63 64 64 65 function Picker:open() 65 - if not self.fn or not self.on_close then 66 - vim.notify("Picker must have `fn` and `on_close`", vim.log.levels.ERROR) 67 - return 68 - end 69 - 70 66 local accepted 71 67 local cancelled 72 68 73 - self.view = View:new() 74 - self.view.picker = self 69 + self.view = View:new(self) 75 70 76 71 coroutine.wrap(function() 77 72 self.view:open()
+3 -1
lua/artio/view.lua
··· 57 57 local View = {} 58 58 View.__index = View 59 59 60 - function View:new() 60 + ---@param picker artio.Picker 61 + function View:new(picker) 61 62 return setmetatable({ 63 + picker = picker, 62 64 closed = false, 63 65 win = { 64 66 height = 0,