From 3fa3f197277528ae9fef75c2d6bf9fe147611e65 Mon Sep 17 00:00:00 2001 From: TheLeoP Date: Wed, 18 Oct 2023 12:54:42 -0500 Subject: [PATCH] chore!: refactor --- doc/tags | 11 +++++++++++ lua/project_nvim/config.lua | 9 ++------- lua/telescope/_extensions/projects.lua | 23 +++++++++-------------- 3 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 doc/tags diff --git a/doc/tags b/doc/tags new file mode 100644 index 0000000..64308ce --- /dev/null +++ b/doc/tags @@ -0,0 +1,11 @@ +project.nvim-Telescope-Projects-Picker project.nvim.txt /*project.nvim-Telescope-Projects-Picker* +project.nvim-Telescope-mappings project.nvim.txt /*project.nvim-Telescope-mappings* +project.nvim-api project.nvim.txt /*project.nvim-api* +project.nvim-configuration project.nvim.txt /*project.nvim-configuration* +project.nvim-contributing project.nvim.txt /*project.nvim-contributing* +project.nvim-features project.nvim.txt /*project.nvim-features* +project.nvim-installation project.nvim.txt /*project.nvim-installation* +project.nvim-project.nvim project.nvim.txt /*project.nvim-project.nvim* +project.nvim-requirements project.nvim.txt /*project.nvim-requirements* +project.nvim-table-of-contents project.nvim.txt /*project.nvim-table-of-contents* +project.nvim.txt project.nvim.txt /*project.nvim.txt* diff --git a/lua/project_nvim/config.lua b/lua/project_nvim/config.lua index b89debf..f942eaf 100644 --- a/lua/project_nvim/config.lua +++ b/lua/project_nvim/config.lua @@ -41,14 +41,9 @@ M.defaults = { -- telescope datapath = vim.fn.stdpath("data"), - -- Allows the user to declare a custom callback to execute on project selection - on_project_selection = false, - -- Whether or no to call find_files on project selection - -- on_project_selection: find_files gets called if the callback - -- on_project_selection returns true - ---@type "always"|"on_project_selection" - find_files = "always", + ---@type boolean|fun(prompt_bufnr: number): boolean + find_files = true, } ---@type ProjectOptions diff --git a/lua/telescope/_extensions/projects.lua b/lua/telescope/_extensions/projects.lua index bb7ab6f..42c82ef 100644 --- a/lua/telescope/_extensions/projects.lua +++ b/lua/telescope/_extensions/projects.lua @@ -137,22 +137,17 @@ end local on_project_selected = function(prompt_bufnr) local open_find_files = false - local switch = { - always = find_project_files, - on_project_selection = function(prompt_bufnr) - if open_find_files then - find_project_files(prompt_bufnr) - else - actions.close(prompt_bufnr) - end - end, - } - if config.options.on_project_selection then - _, open_find_files = pcall(config.options.on_project_selection, prompt_bufnr) + if vim.is_callable(config.options.find_files) then + open_find_files = config.options.find_files(prompt_bufnr) + else + open_find_files = config.options.find_files --[[@as boolean]] end - if switch[config.options.find_files] then - switch[config.options.find_files](prompt_bufnr) + + if open_find_files then + find_project_files(prompt_bufnr) + else + actions.close(prompt_bufnr) end end