There will be some inevitable churn for the next week as I settle on the api!
This is a WORK IN PROGRESS repo :)
Look in queries/ to see which languages are currently supported.
- I want to write tests for a bunch of stuff.
- ...
- stability and profitability
The Refactoring library based off the Refactoring book by Martin Fowler
Requirements:
NEOVIM NIGHTLY The plugin is tested on neovim nightly, please make sure you are on nightly before submitting an issue with the plugin.
Plugins:
- Treesitter
- Lsp
- Plenary
Packer setup:
use {
"ThePrimeagen/refactoring.nvim",
requires = {
{"nvim-lua/plenary.nvim"},
{"nvim-treesitter/nvim-treesitter"}
}
}
Example Config:
local refactor = require("refactoring")
refactor.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", "<CR>", refactor)
map("n", "<CR>", refactor)
return true
end
}):find()
end
vim.api.nvim_set_keymap("v", "<Leader>re", [[ <Esc><Cmd>lua require('refactoring').refactor('Extract Function')<CR>]], {noremap = true, silent = true, expr = false})
vim.api.nvim_set_keymap("v", "<Leader>rf", [[ <Esc><Cmd>lua require('refactoring').refactor('Extract Function To File')<CR>]], {noremap = true, silent = true, expr = false})
vim.api.nvim_set_keymap("v", "<Leader>rt", [[ <Esc><Cmd>lua M.refactors()<CR>]], {noremap = true, silent = true, expr = false})