Skip to content

Commit 3569e4e

Browse files
committed
Allow refactoring (plus minor tweaks)
1 parent 2be2cae commit 3569e4e

File tree

5 files changed

+89
-11
lines changed

5 files changed

+89
-11
lines changed

init.lua

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ vim.opt.inccommand = 'split'
154154
vim.opt.cursorline = true
155155

156156
-- Minimal number of screen lines to keep above and below the cursor.
157-
-- vim.opt.scrolloff = 10
157+
vim.opt.scrolloff = 10
158158

159159
-- [[ Basic Keymaps ]]
160160
-- See `:help vim.keymap.set()`
@@ -384,11 +384,20 @@ require('lazy').setup({
384384
-- You can put your default mappings / updates / etc. in here
385385
-- All the info you're looking for is in `:help telescope.setup()`
386386
--
387-
-- defaults = {
388-
-- mappings = {
389-
-- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
390-
-- },
391-
-- },
387+
defaults = {
388+
-- mappings = {
389+
-- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
390+
-- },
391+
layout_strategy = 'vertical',
392+
layout_config = {
393+
vertical = {
394+
width = 0.9,
395+
height = 0.9,
396+
preview_height = 0.6,
397+
preview_cutoff = 0,
398+
},
399+
},
400+
},
392401
-- pickers = {}
393402
extensions = {
394403
['ui-select'] = {

lazy-lock.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"nvim-treesitter-context": { "branch": "master", "commit": "198720b4016af04c9590f375d714d5bf8afecc1a" },
2323
"nvim-web-devicons": { "branch": "master", "commit": "ab4cfee554e501f497bce0856788d43cf2eb93d7" },
2424
"plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" },
25+
"refactoring.nvim": { "branch": "master", "commit": "5268cc6add06ba8862492063341a568d18d65fb6" },
2526
"telescope-fzf-native.nvim": { "branch": "main", "commit": "2a5ceff981501cff8f46871d5402cd3378a8ab6a" },
2627
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
2728
"telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },

lua/custom/plugins/init.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
-- I promise not to create any merge conflicts in this directory :)
33
--
44
-- See the kickstart.nvim README for more information
5+
--
6+
-- When a file has been detected to have been changed outside of Vim and it has not been changed inside of Vim, automatically read it again.
7+
vim.opt.autoread = true
8+
59
return {
610
vim.keymap.set('n', '<leader>sm', function()
711
require('telescope.builtin').live_grep { search_dirs = { '/home/ccs/missbrenner/Documents/ns-3/ns3-mmwave-iab/src/mmwave/' } }
8-
end, { desc = '[S]earch [M]mwave files' }),
12+
end, { desc = '[S]earch [M]mwave File Contents' }),
913
}

lua/custom/plugins/refactoring.lua

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
return {
2+
'ThePrimeagen/refactoring.nvim',
3+
dependencies = {
4+
'nvim-lua/plenary.nvim',
5+
'nvim-treesitter/nvim-treesitter',
6+
},
7+
lazy = false,
8+
config = function()
9+
require('refactoring').setup {
10+
prompt_func_return_type = {
11+
go = false,
12+
java = false,
13+
14+
cpp = false,
15+
c = false,
16+
h = false,
17+
hpp = false,
18+
cxx = false,
19+
},
20+
prompt_func_param_type = {
21+
go = false,
22+
java = false,
23+
24+
cpp = false,
25+
c = false,
26+
h = false,
27+
hpp = false,
28+
cxx = false,
29+
},
30+
printf_statements = {},
31+
print_var_statements = {},
32+
show_success_message = true, -- shows a message with information about the refactor on success
33+
-- i.e. [Refactor] Inlined 3 variable occurrences
34+
}
35+
end,
36+
vim.keymap.set({ 'n', 'x' }, '<leader>cr', function()
37+
return require('refactoring').refactor 'Code Refactor'
38+
end, { expr = true, desc = '[C]ode [R]efactor' }),
39+
vim.keymap.set({ 'n', 'x' }, '<leader>cre', function()
40+
return require('refactoring').refactor 'Extract Function'
41+
end, { expr = true, desc = '[R]efactor [E]xtract Function' }),
42+
vim.keymap.set({ 'n', 'x' }, '<leader>crf', function()
43+
return require('refactoring').refactor 'Extract Function To File'
44+
end, { expr = true, desc = '[R]efactor Extract Function To [F]ile' }),
45+
vim.keymap.set({ 'n', 'x' }, '<leader>crv', function()
46+
return require('refactoring').refactor 'Extract Variable'
47+
end, { expr = true, desc = '[R]efactor Extract [V]ariable' }),
48+
vim.keymap.set({ 'n', 'x' }, '<leader>crI', function()
49+
return require('refactoring').refactor 'Inline Function'
50+
end, { expr = true, desc = '[R]efactor [I]nline Function' }),
51+
vim.keymap.set({ 'n', 'x' }, '<leader>cri', function()
52+
return require('refactoring').refactor 'Inline Variable'
53+
end, { expr = true, desc = '[R]efactor [I]nline Variable' }),
54+
55+
vim.keymap.set({ 'n', 'x' }, '<leader>crbb', function()
56+
return require('refactoring').refactor 'Extract Block'
57+
end, { expr = true, desc = '[R]efactor Extract [B]lock' }),
58+
vim.keymap.set({ 'n', 'x' }, '<leader>crbf', function()
59+
return require('refactoring').refactor 'Extract Block To File'
60+
end, { expr = true, desc = '[R]efactor Extract [B]lock To [F]ile' }),
61+
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
return {
2-
"nvim-treesitter/nvim-treesitter-context",
2+
'nvim-treesitter/nvim-treesitter-context',
33
config = function()
4-
require'treesitter-context'.setup{
4+
require('treesitter-context').setup {
55
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
66
multiwindow = false, -- Enable multiwindow support.
77
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
88
min_window_height = 0, -- Minimum editor window height to enable context. Values <= 0 mean no limit.
99
line_numbers = true,
1010
multiline_threshold = 20, -- Maximum number of lines to show for a single context
11-
trim_scope = 'outer', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
12-
mode = 'topline', -- Line used to calculate context. Choices: 'cursor', 'topline'
11+
trim_scope = 'inner', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
12+
mode = 'cursor', -- Line used to calculate context. Choices: 'cursor', 'topline'
1313
-- Separator between context and content. Should be a single character string, like '-'.
1414
-- When separator is set, the context will only show up when there are at least 2 lines above cursorline.
1515
separator = nil,
1616
zindex = 20, -- The Z-index of the context window
1717
on_attach = nil, -- (fun(buf: integer): boolean) return false to disable attaching
1818
}
1919
end,
20+
vim.keymap.set('n', '[c', function()
21+
require('treesitter-context').go_to_context(vim.v.count1)
22+
end, { silent = true, desc = '[C]ontext (upwards)' }),
2023
}

0 commit comments

Comments
 (0)