From 451718043a7e30c2ce9b80bcdd827218aa0d4433 Mon Sep 17 00:00:00 2001 From: ChrisHilborne Date: Wed, 22 May 2024 22:15:49 +0200 Subject: [PATCH] Refactor added --- init.lua | 10 ++++++++++ lua/custom/plugins/refactor.lua | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lua/custom/plugins/refactor.lua diff --git a/init.lua b/init.lua index 170db484..7f01b231 100755 --- a/init.lua +++ b/init.lua @@ -171,6 +171,16 @@ require('lazy').setup({ end, }, }, + config = function() + -- load refactoring Telescope extension + require("telescope").load_extension("refactoring") + + vim.keymap.set( + { "n", "x" }, + "rr", + function() require('telescope').extensions.refactoring.refactors() end + ) + end, }, { diff --git a/lua/custom/plugins/refactor.lua b/lua/custom/plugins/refactor.lua new file mode 100644 index 00000000..a3f37f02 --- /dev/null +++ b/lua/custom/plugins/refactor.lua @@ -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", "re", function() require('refactoring').refactor('Extract Function') end + , { desc = '[E]xtract Function' }) + vim.keymap.set("x", "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", "rv", function() require('refactoring').refactor('Extract Variable') end + , { desc = 'Extract [V]ariable' }) + -- Extract variable supports only visual mode + vim.keymap.set("n", "rI", function() require('refactoring').refactor('Inline Function') end + , { desc = '[I]nline Function' }) + -- Inline func supports only normal + vim.keymap.set({ "n", "x" }, "ri", function() require('refactoring').refactor('Inline Variable') end + , { desc = '[I]nline Variable' }) + -- Inline var supports both normal and visual mode + + vim.keymap.set("n", "rb", function() require('refactoring').refactor('Extract Block') end, + { desc = 'Extract [B]lock' }) + vim.keymap.set("n", "rbf", function() require('refactoring').refactor('Extract Block To File') end, + { desc = 'Extract [B]lock to [F]ile' }) + -- Extract block supports only normal mode + end, + }, +}