Skip to content

Commit

Permalink
chore!: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoP committed Oct 18, 2023
1 parent 1b2d79e commit 3fa3f19
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
11 changes: 11 additions & 0 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -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*
9 changes: 2 additions & 7 deletions lua/project_nvim/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 9 additions & 14 deletions lua/telescope/_extensions/projects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3fa3f19

Please sign in to comment.