Skip to content

Commit 4517180

Browse files
committed
Refactor added
1 parent 3c296e8 commit 4517180

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

init.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ require('lazy').setup({
171171
end,
172172
},
173173
},
174+
config = function()
175+
-- load refactoring Telescope extension
176+
require("telescope").load_extension("refactoring")
177+
178+
vim.keymap.set(
179+
{ "n", "x" },
180+
"<leader>rr",
181+
function() require('telescope').extensions.refactoring.refactors() end
182+
)
183+
end,
174184
},
175185

176186
{

lua/custom/plugins/refactor.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
return {
2+
{
3+
"ThePrimeagen/refactoring.nvim",
4+
dependencies = {
5+
"nvim-lua/plenary.nvim",
6+
"nvim-treesitter/nvim-treesitter",
7+
},
8+
config = function()
9+
require("refactoring").setup()
10+
vim.keymap.set("x", "<leader>re", function() require('refactoring').refactor('Extract Function') end
11+
, { desc = '[E]xtract Function' })
12+
vim.keymap.set("x", "<leader>rf", function() require('refactoring').refactor('Extract Function To File') end,
13+
{ desc = 'Extract Function to [F]ile' })
14+
-- Extract function supports only visual mode
15+
vim.keymap.set("x", "<leader>rv", function() require('refactoring').refactor('Extract Variable') end
16+
, { desc = 'Extract [V]ariable' })
17+
-- Extract variable supports only visual mode
18+
vim.keymap.set("n", "<leader>rI", function() require('refactoring').refactor('Inline Function') end
19+
, { desc = '[I]nline Function' })
20+
-- Inline func supports only normal
21+
vim.keymap.set({ "n", "x" }, "<leader>ri", function() require('refactoring').refactor('Inline Variable') end
22+
, { desc = '[I]nline Variable' })
23+
-- Inline var supports both normal and visual mode
24+
25+
vim.keymap.set("n", "<leader>rb", function() require('refactoring').refactor('Extract Block') end,
26+
{ desc = 'Extract [B]lock' })
27+
vim.keymap.set("n", "<leader>rbf", function() require('refactoring').refactor('Extract Block To File') end,
28+
{ desc = 'Extract [B]lock to [F]ile' })
29+
-- Extract block supports only normal mode
30+
end,
31+
},
32+
}

0 commit comments

Comments
 (0)