-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathsnacks.lua
63 lines (59 loc) · 1.76 KB
/
snacks.lua
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
57
58
59
60
61
62
63
local log = require("leetcode.logger")
local t = require("leetcode.translator")
local picker = require("snacks.picker")
local language_picker = require("leetcode.picker.language")
---@param question lc.ui.Question
return function(question, cb)
local items = language_picker.items(question.q.code_snippets)
local finder_items = {}
local completed = false
for _, item in ipairs(items) do
local text = language_picker.ordinal(item.value)
table.insert(finder_items, {
text = text,
item = item,
})
end
picker.pick({
source = "select",
items = finder_items,
format = function(item)
local ret = {}
vim.tbl_map(function(col)
if type(col) == "table" then
ret[#ret + 1] = col
else
ret[#ret + 1] = { col }
end
ret[#ret + 1] = { " " }
end, item.item.entry)
return ret
end,
title = t("Available Languages"),
layout = {
preview = false,
layout = {
height = math.floor(math.min(vim.o.lines * 0.8 - 10, #items + 2) + 0.5),
},
},
actions = {
confirm = function(p, item)
if completed then
return
end
completed = true
p:close()
vim.schedule(function()
language_picker.select(item.item.value.t, question, cb)
end)
end,
},
on_close = function()
if completed then
return
end
completed = true
log.warn("No selection")
end,
})
end