aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorAriel DAlessandro <ariel.dalessandro@auto1.com>2021-08-14 12:20:33 +0200
committerAriel DAlessandro <ariel.dalessandro@auto1.com>2021-08-14 12:20:33 +0200
commit7c8ba7a40a3209fc1cf483e82f62560b4dff1a06 (patch)
tree9240909a0aa60dee6ef7aaa2c471f34b419126b9 /lua
parent9d7663ca36fcefcacbefb20807e9379d7316ddf2 (diff)
downloadnvim-conf-7c8ba7a40a3209fc1cf483e82f62560b4dff1a06.tar.gz
nvim-conf-7c8ba7a40a3209fc1cf483e82f62560b4dff1a06.zip
add packer and refactoring
Diffstat (limited to 'lua')
-rw-r--r--lua/alpha/init.lua1
-rw-r--r--lua/alpha/refactoring.lua35
-rw-r--r--lua/plugins.lua11
3 files changed, 47 insertions, 0 deletions
diff --git a/lua/alpha/init.lua b/lua/alpha/init.lua
index fa7dd53..c403f8c 100644
--- a/lua/alpha/init.lua
+++ b/lua/alpha/init.lua
@@ -1 +1,2 @@
require("alpha.telescope")
+require("alpha.refactoring")
diff --git a/lua/alpha/refactoring.lua b/lua/alpha/refactoring.lua
new file mode 100644
index 0000000..262400f
--- /dev/null
+++ b/lua/alpha/refactoring.lua
@@ -0,0 +1,35 @@
+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()
+ require("telescope.pickers").new({}, {
+ prompt_title = "refactors",
+ finder = require("telescope.finders").new_table({
+ results = require("refactoring").get_refactors(),
+ }),
+ sorter = require("telescope.config").values.generic_sorter({}),
+ 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", [[ <Cmd>lua require('refactoring').refactor('Extract Function')<CR>]], {noremap = true, silent = true, expr = false})
+vim.api.nvim_set_keymap("v", "<Leader>rf", [[ <Cmd>lua require('refactoring').refactor('Extract Function To File')<CR>]], {noremap = true, silent = true, expr = false})
+vim.api.nvim_set_keymap("v", "<Leader>rt", [[ <Cmd>lua M.refactors()<CR>]], {noremap = true, silent = true, expr = false})
diff --git a/lua/plugins.lua b/lua/plugins.lua
new file mode 100644
index 0000000..ebe891d
--- /dev/null
+++ b/lua/plugins.lua
@@ -0,0 +1,11 @@
+vim.cmd [[packadd packer.nvim]]
+
+return require('packer').startup(function()
+ use {
+ "ThePrimeagen/refactoring.nvim",
+ requires = {
+ {"nvim-lua/plenary.nvim"},
+ {"nvim-treesitter/nvim-treesitter"}
+ }
+ }
+end)