diff --git a/lua/config/refactoring.lua b/lua/config/refactoring.lua new file mode 100644 index 0000000..617fc92 --- /dev/null +++ b/lua/config/refactoring.lua @@ -0,0 +1,39 @@ +local refactoring = require("refactoring") +refactoring.setup() + +-- telescope refactoring helper +local function refactor(prompt_bufnr) + local content = require("telescope.actions.state").get_selected_entry( + prompt_bufnr + ) + require("telescope.actions").close(prompt_bufnr) + require("refactoring").refactor(content.value) +end + +-- NOTE: M is a global object +-- for the sake of simplicity in this example +-- you can extract this function and the helper above +-- and then require the file and call the extracted function +-- in the mappings below +M = {} +M.refactors = function() + local opts = require("telescope.themes").get_cursor() -- set personal telescope options + require("telescope.pickers").new(opts, { + prompt_title = "refactors", + finder = require("telescope.finders").new_table({ + results = require("refactoring").get_refactors(), + }), + sorter = require("telescope.config").values.generic_sorter(opts), + attach_mappings = function(_, map) + map("i", "", refactor) + map("n", "", refactor) + return true + end + }):find() +end + +vim.api.nvim_set_keymap("v", "re", [[ lua require('refactoring').refactor('Extract Function')]], {noremap = true, silent = true, expr = false}) +vim.api.nvim_set_keymap("v", "rf", [[ lua require('refactoring').refactor('Extract Function To File')]], {noremap = true, silent = true, expr = false}) +vim.api.nvim_set_keymap("v", "rt", [[ lua M.refactors()]], {noremap = true, silent = true, expr = false}) + +return M diff --git a/lua/plugins.lua b/lua/plugins.lua index e505d42..32535cc 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -132,6 +132,17 @@ local function usePlugins(use, use_rocks) -- tag = 'release' -- To use the latest release } + -- Refactoring + use { + "ThePrimeagen/refactoring.nvim", + requires = { + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter" + }, + disable = true, + config = [[require 'config.refactoring']] + } + -- Analyze startup time use 'tweekmonster/startuptime.vim'