Custom actions for finder?
Is your feature request related to a problem? Please describe. I created a telescope plugin for myself that takes a filepath and presents options to open it in the current window, new tab, vsplit left, vsplit right, split above, and split below. Ideally, I would like to get the filepath that was selected from the lspsaga finder UI to open up my telescope picker to choose the desired action. This would normalize my bindings across neovim while reducing steps to remember.
Describe the solution you'd like There's two options that could work:
- Support something like the following:
require("lspsaga").setup({ finder = { keys = { "<cr>" = function (filepath) ... end }, }, }) - Create module-level functions for common actions that one could replace with their own implementations. Less ideal monkey-patching actions but it would work, and I have an emacs-inspired advising system that would make it more manageable.
telescope = require('telescope') telescope.actions.open = function (filepath) telescope._extensions.find_menu.find_menu({ filepath = filepath }) end
Describe alternatives you've considered I looked at the finder implementation and saw that it's mostly iterating the config settings for keys, so was thinking I could do something like the following:
require("lspsaga").setup({
finder = {
keys = {
"Telescope file_menu filepath=" = "<CR>",
},
},
})
But that doesn't seem to work, I'll have to check but maybe unsupported commands are stripped from the config?
I could fork it and make my changes, but then I'll have to be on top of your upstream changes and I'd much rather try and find a way to make lspsaga better than create a worse version of it.
Additional context
Open to alternative ideas here!
Found a discussion that's nearly identical https://github.com/orgs/nvimdev/discussions/1495#discussion-7301203
That said, it sparked an alternative idea:
require("lspsaga").setup({
finder = {
keys = {
open = "<cr>" -- Set Enter to open the file
},
actions = {
open = function (filepath) ... end
}
},
})
- It wouldn't change the existing
keysconfiguration shape - It would be trivial to implement:
if config.finder.actions[action] { config.finder.actions[action](fname) } else { vim.cmd[action](fname) } - That conditional would be applied https://github.com/nvimdev/lspsaga.nvim/blob/da8a66c53241876bba140980469876db3a183604/lua/lspsaga/finder/init.lua#L441
- The conditional would also apply https://github.com/nvimdev/lspsaga.nvim/blob/da8a66c53241876bba140980469876db3a183604/lua/lspsaga/finder/init.lua#L447
- This system should even support new\custom actions if I understand this right!
- I think it's a reasonable compromise to prevent redefining the actions defined in https://github.com/nvimdev/lspsaga.nvim/blob/da8a66c53241876bba140980469876db3a183604/lua/lspsaga/finder/init.lua#L409
If you're on board with that route I'm happy to draft a PR. Thoughts?
Decided to try drafting a PR anyway given it's a pretty minimal amount of changes.