Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions lua/esqueleto/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,58 @@ M.selecttemplate = function(templates, opts)
end)
end

function M.builtin_finder(templates, opts)
local templatenames = vim.tbl_keys(templates)
vim.ui.select(templatenames, { prompt = "Select skeleton to use:" }, function(choice)
if templates[choice] then
M.writetemplate(vim.loop.fs_realpath(templates[choice]), opts)
else
vim.notify("[esqueleto] No template selected, leaving buffer empty", vim.log.levels.INFO)
end
end)
end
---@param templates {[string]:string}
---@param opts table
---@return nil
function M.telescope_finder(templates, opts)
local telescope_exist, pickers = pcall(require, "telescope_pickers")
if not telescope_exist then
return vim.notify("[esqueleto] Telescope does not exist", vim.log.levels.WARN)
end
local finders = require("telescope.finders")
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local templatenames = {}
for key in pairs(templates) do
table.insert(templatenames, key)
end
pickers
.new({}, {
prompt_title = "Select skeleton to use",
previewer = _TelescopeConfigurationValues.file_previewer({}),
finder = finders.new_table({
results = templatenames,
entry_maker = function(entry)
return {
value = entry,
display = entry,
ordinal = entry,
filename = templates[entry],
}
end,
}),
sorter = _TelescopeConfigurationValues.generic_sorter({}),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
M.writetemplate(vim.loop.fs_realpath(templates[selection.value]), opts)
end)
return true
end,
})
:find()
end
--- Insert template on current buffer
---@param opts table Plugin configuration table
M.inserttemplate = function(opts)
Expand Down