Refactor added

This commit is contained in:
ChrisHilborne 2024-05-22 22:15:49 +02:00
parent 3c296e858c
commit 451718043a
2 changed files with 42 additions and 0 deletions

View File

@ -171,6 +171,16 @@ require('lazy').setup({
end, end,
}, },
}, },
config = function()
-- load refactoring Telescope extension
require("telescope").load_extension("refactoring")
vim.keymap.set(
{ "n", "x" },
"<leader>rr",
function() require('telescope').extensions.refactoring.refactors() end
)
end,
}, },
{ {

View File

@ -0,0 +1,32 @@
return {
{
"ThePrimeagen/refactoring.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
},
config = function()
require("refactoring").setup()
vim.keymap.set("x", "<leader>re", function() require('refactoring').refactor('Extract Function') end
, { desc = '[E]xtract Function' })
vim.keymap.set("x", "<leader>rf", function() require('refactoring').refactor('Extract Function To File') end,
{ desc = 'Extract Function to [F]ile' })
-- Extract function supports only visual mode
vim.keymap.set("x", "<leader>rv", function() require('refactoring').refactor('Extract Variable') end
, { desc = 'Extract [V]ariable' })
-- Extract variable supports only visual mode
vim.keymap.set("n", "<leader>rI", function() require('refactoring').refactor('Inline Function') end
, { desc = '[I]nline Function' })
-- Inline func supports only normal
vim.keymap.set({ "n", "x" }, "<leader>ri", function() require('refactoring').refactor('Inline Variable') end
, { desc = '[I]nline Variable' })
-- Inline var supports both normal and visual mode
vim.keymap.set("n", "<leader>rb", function() require('refactoring').refactor('Extract Block') end,
{ desc = 'Extract [B]lock' })
vim.keymap.set("n", "<leader>rbf", function() require('refactoring').refactor('Extract Block To File') end,
{ desc = 'Extract [B]lock to [F]ile' })
-- Extract block supports only normal mode
end,
},
}