feat: refactoring.nvim

This commit is contained in:
punkfairie 2025-01-03 20:02:38 -08:00
parent 6b45da03e2
commit 4422d9f41a
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696
3 changed files with 128 additions and 0 deletions

View file

@ -56,6 +56,7 @@ with final.pkgs.lib; let
todo-comments-nvim
aerial-nvim
fzf-lua
refactoring-nvim
# Treesitter
nvim-treesitter-textobjects

View file

@ -7,6 +7,7 @@ return {
req('gitsigns-nvim'),
req('grug-far-nvim'),
req('neo-tree-nvim'),
req('refactoring-nvim'),
req('todo-comments-nvim'),
req('trouble-nvim'),
req('which-key-nvim'),

View file

@ -0,0 +1,126 @@
return {
'refactoring.nvim',
event = { 'BufReadPre', 'BufNewFile' },
keys = {
{ '<LEADER>r', '', desc = '+refactor', mode = { 'n', 'v' } },
{
'<LEADER>rb',
function()
require('refactoring').refactor('Extract Block')
end,
desc = 'extract block',
},
{
'<LEADER>rc',
function()
require('refactoring').debug.cleanup({})
end,
desc = 'debug cleanup',
},
{
'<LEADER>rf',
function()
require('refactoring').refactor('Extract Block To File')
end,
desc = 'extract block to file',
},
{
'<LEADER>rf',
function()
require('refactoring').refactor('Extract Function')
end,
mode = 'v',
desc = 'extract function',
},
{
'<LEADER>rF',
function()
require('refactoring').refactor('Extract Function To File')
end,
mode = 'v',
desc = 'extract function to file',
},
{
'<LEADER>ri',
function()
require('refactoring').refactor('Inline Variable')
end,
mode = { 'n', 'v' },
desc = 'inline variable',
},
{
'<LEADER>rp',
function()
require('refactoring').debug.print_var({ normal = true })
end,
desc = 'debug print variable',
},
{
'<LEADER>rp',
function()
require('refactoring').debug.print_var()
end,
mode = 'v',
desc = 'debug print variable',
},
{
'<LEADER>rP',
function()
require('refactoring').debug.printf({ below = false })
end,
desc = 'debug print',
},
{
'<LEADER>rs',
function()
require('fzf-lua').fzf_exec(require('refactoring').get_refactors(), {
fzf_opts = {},
fzf_colors = true,
actions = {
['default'] = function(selected)
require('refactoring').refactor(selected[1])
end,
},
})
end,
mode = 'v',
desc = 'refactor',
},
{
'<LEADER>rx',
function()
require('refactoring').refactor('Extract Variable')
end,
mode = 'v',
desc = 'extract variable',
},
},
before = function()
require('lz.n').trigger_load({ 'plenary.nvim', 'nvim-treesitter' })
end,
after = function()
require('refactoring').setup({
prompt_func_param_type = {
go = false,
java = false,
cpp = false,
c = false,
h = false,
hpp = false,
cxx = false,
},
prompt_func_return_type = {
go = false,
java = false,
cpp = false,
c = false,
h = false,
hpp = false,
cxx = false,
},
printf_statements = {},
print_var_statements = {},
show_success_message = false,
})
end,
}