-
-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Hi!
So I've been using a feature for a while on my side with some hacked code and would like to integrate it better in the main repo, so I am asking for how to best do it. The concept is as follow: when the function is called, a telescope picker is opened with current opened projects using opened_projects registry. When a selection is made, the most recent buffer opened in that project is opened (should also lcd if enabled). Here are some screenshots:
- Example of classic telescope repo.
- When 2 projects have been opened and calling the function.
Link to a hacky implementation of mine: phgz@e1236c1
In there, I add a get_project_paths() function to be used by user and call user_opts.post_action(dir) if it's defined. Other than that a (I think) bug fix calling project_live_grep with user_opts instead of list_opts and a previous fix on autocmd that I mentioned a while ago, which I saw on one of your dev branch you fixed.
On the user part, here's how I define my command: I first do the inventory of active buffers and "map" them to an opened project. Then I use that list to feed to the search_dirs and set the post action to execute.
vim.keymap.set("n", "<leader>s", function() --
local project_paths = require("telescope._extensions.repo.autocmd_lcd").get_project_paths()
local context = api.nvim_get_context({ types = { "bufs" } })
local bufs = call("msgpackparse", { context["bufs"] })[4]
local open_projects = vim.iter.filter(function(project_path)
local found = vim.iter(bufs):find(function(buf_path)
return vim.startswith(buf_path["f"], project_path)
end)
return found or false
end, project_paths)
require("telescope").extensions.repo.list(vim.tbl_extend("error", dropdown_theme, {
search_dirs = vim.tbl_isempty(open_projects) and { "" } or open_projects,
post_action = post_action_fn,
prompt = " (opened projects)",
}))
end)My post action function takes the selected project by the user and browses jumplist to find most recent file of that project and then simply perform a vim.cmd.edit(to_edit) on the found file.
So either there could be a possibility to leave the opportunity to the users to define their own post action, or simply add a function as a whole (like telescope.extensions.repo.switch) embedded in telescope-repo` and make it public in the API.
Thanks!