Files
LazyVim/lua/lazyvim/plugins/extras/editor/refactoring.lua
Iordanis Petkakis b45d4ed62c fix(refactoring): use pick for both Telescope and fzf-lua (#3769)
## What is this PR for?
Provide a `pick` function to `refactoring.nvim` similar to
`project.nvim`
<!-- Describe the big picture of your changes to communicate to the
maintainers
  why we should accept this pull request. -->

## Does this PR fix an existing issue?
Fixes #3762
<!--
  If this PR fixes any issues, please link to the issue here.
  Fixes #<issue_number>
-->

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
2024-06-23 07:01:58 +02:00

148 lines
3.5 KiB
Lua

local pick = function()
if LazyVim.pick.picker.name == "telescope" then
return require("telescope").extensions.refactoring.refactors()
elseif LazyVim.pick.picker.name == "fzf" then
local fzf_lua = require("fzf-lua")
local results = require("refactoring").get_refactors()
local refactoring = require("refactoring")
local opts = {
fzf_opts = {},
fzf_colors = true,
actions = {
["default"] = function(selected)
refactoring.refactor(selected[1])
end,
},
}
fzf_lua.fzf_exec(results, opts)
end
end
return {
{
"ThePrimeagen/refactoring.nvim",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
},
keys = {
{ "<leader>r", "", desc = "+refactor", mode = { "n", "v" } },
{
"<leader>rs",
pick,
mode = "v",
desc = "Refactor",
},
{
"<leader>ri",
function()
require("refactoring").refactor("Inline Variable")
end,
mode = { "n", "v" },
desc = "Inline Variable",
},
{
"<leader>rb",
function()
require("refactoring").refactor("Extract Block")
end,
desc = "Extract Block",
},
{
"<leader>rf",
function()
require("refactoring").refactor("Extract Block To File")
end,
desc = "Extract Block To File",
},
{
"<leader>rP",
function()
require("refactoring").debug.printf({ below = false })
end,
desc = "Debug Print",
},
{
"<leader>rp",
function()
require("refactoring").debug.print_var({ normal = true })
end,
desc = "Debug Print Variable",
},
{
"<leader>rc",
function()
require("refactoring").debug.cleanup({})
end,
desc = "Debug Cleanup",
},
{
"<leader>rf",
function()
require("refactoring").refactor("Extract Function")
end,
mode = "v",
desc = "Extract Function",
},
{
"<leader>rF",
function()
require("refactoring").refactor("Extract Function To File")
end,
mode = "v",
desc = "Extract Function To File",
},
{
"<leader>rx",
function()
require("refactoring").refactor("Extract Variable")
end,
mode = "v",
desc = "Extract Variable",
},
{
"<leader>rp",
function()
require("refactoring").debug.print_var()
end,
mode = "v",
desc = "Debug Print Variable",
},
},
opts = {
prompt_func_return_type = {
go = false,
java = false,
cpp = false,
c = false,
h = false,
hpp = false,
cxx = false,
},
prompt_func_param_type = {
go = false,
java = false,
cpp = false,
c = false,
h = false,
hpp = false,
cxx = false,
},
printf_statements = {},
print_var_statements = {},
show_success_message = true, -- shows a message with information about the refactor on success
-- i.e. [Refactor] Inlined 3 variable occurrences
},
config = function(_, opts)
require("refactoring").setup(opts)
if LazyVim.has("telescope.nvim") then
LazyVim.on_load("telescope.nvim", function()
require("telescope").load_extension("refactoring")
end)
end
end,
},
}