From dd25e3946ec9d63d2b5cf4335f8dbed06cdd6ab1 Mon Sep 17 00:00:00 2001 From: azan Date: Wed, 2 Oct 2024 18:02:36 +0300 Subject: [PATCH 1/3] feat(finder): add telescope finder --- lua/esqueleto/utils.lua | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lua/esqueleto/utils.lua b/lua/esqueleto/utils.lua index 4d408c3..47a6655 100644 --- a/lua/esqueleto/utils.lua +++ b/lua/esqueleto/utils.lua @@ -174,6 +174,56 @@ 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 + +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[templatenames], + } + end, + }), + sorter = _TelescopeConfigurationValues.generic_sorcer({}), + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + M.writetemplate(selection.filename, opts) + end) + return true + end, + }) + :find() +end --- Insert template on current buffer ---@param opts table Plugin configuration table M.inserttemplate = function(opts) From f21311d5cddfd8a818565c3dac6aa0a84ca01a4b Mon Sep 17 00:00:00 2001 From: azan Date: Wed, 2 Oct 2024 18:19:44 +0300 Subject: [PATCH 2/3] fix(utils): telescope misspell in sorter --- lua/esqueleto/utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/esqueleto/utils.lua b/lua/esqueleto/utils.lua index 47a6655..b4b5901 100644 --- a/lua/esqueleto/utils.lua +++ b/lua/esqueleto/utils.lua @@ -212,7 +212,7 @@ function M.telescope_finder(templates, opts) } end, }), - sorter = _TelescopeConfigurationValues.generic_sorcer({}), + sorter = _TelescopeConfigurationValues.generic_sorter({}), attach_mappings = function(prompt_bufnr) actions.select_default:replace(function() actions.close(prompt_bufnr) From b0055911d31b91ed3b96bb9b3abf3d76ab5f398c Mon Sep 17 00:00:00 2001 From: azan Date: Wed, 2 Oct 2024 18:38:15 +0300 Subject: [PATCH 3/3] fix(telescope): symlink resolve --- lua/esqueleto/utils.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lua/esqueleto/utils.lua b/lua/esqueleto/utils.lua index b4b5901..535f26e 100644 --- a/lua/esqueleto/utils.lua +++ b/lua/esqueleto/utils.lua @@ -184,7 +184,9 @@ function M.builtin_finder(templates, opts) 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 @@ -208,7 +210,7 @@ function M.telescope_finder(templates, opts) value = entry, display = entry, ordinal = entry, - filename = templates[templatenames], + filename = templates[entry], } end, }), @@ -217,7 +219,7 @@ function M.telescope_finder(templates, opts) actions.select_default:replace(function() actions.close(prompt_bufnr) local selection = action_state.get_selected_entry() - M.writetemplate(selection.filename, opts) + M.writetemplate(vim.loop.fs_realpath(templates[selection.value]), opts) end) return true end,