aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha
diff options
context:
space:
mode:
authorAriel D'ALessandro <dalessandro.ariel@gmail.com>2021-08-22 18:57:16 +0200
committerAriel D'ALessandro <dalessandro.ariel@gmail.com>2021-08-22 18:57:16 +0200
commit450c8d49b7d4843cbd6af566eafb98693a2d2fda (patch)
tree8927c842bb64773291a5e7bc58f9d3ebb5dc3181 /lua/alpha
parent2f65f4524a084967572dce8277098ff71555b740 (diff)
downloadnvim-conf-450c8d49b7d4843cbd6af566eafb98693a2d2fda.tar.gz
nvim-conf-450c8d49b7d4843cbd6af566eafb98693a2d2fda.zip
add new telecope funcions and add hide bar to tmux
Diffstat (limited to 'lua/alpha')
-rw-r--r--lua/alpha/refactor.lua72
-rw-r--r--lua/alpha/telescope.lua11
-rw-r--r--lua/alpha/telescope_laravel.lua77
3 files changed, 160 insertions, 0 deletions
diff --git a/lua/alpha/refactor.lua b/lua/alpha/refactor.lua
new file mode 100644
index 0000000..dbf4c5f
--- /dev/null
+++ b/lua/alpha/refactor.lua
@@ -0,0 +1,72 @@
+local ts_utils = require("nvim-treesitter.ts_utils")
+
+local M = {}
+
+local get_master_node = function()
+
+ local node = ts_utils.get_node_at_cursor()
+ if node == nil then
+ error("No treesitter parser found.")
+ end
+
+ local start_row = node:start()
+
+ local parent = node:parent()
+ while (parent ~= nil and parent:start() == start_row) do
+ node = parent
+ parent = node:parent()
+ end
+
+
+ return node
+end
+
+
+M.setter_getter = function()
+ local node = get_master_node()
+
+ if node.type(node) ~= 'property_declaration' then
+ error('can not work on a node that is not a property_declaration')
+ end
+
+ local bufnr = vim.api.nvim_get_current_buf()
+ -- ts_utils.update_selection(bufnr, node)
+
+ local p = {}
+ for _, child in ipairs(ts_utils.get_named_children(node)) do
+ -- print(vim.inspect(ts_utils.get_node_text(child, bufnr)))
+ -- print(vim.inspect(child.type(child)))
+ p[node.type(child)] = ts_utils.get_node_text(child, bufnr)[1]
+ end
+
+ -- for this expected to have 2 or more named childs
+ -- visibility modifier
+ -- type_list (optional) could have a ? to be nullable or could have a list
+ -- property_element
+ print(vim.inspect(p))
+
+ local comment = ''
+
+ if (p.type_list == 'array' or p.type_list == nil) then
+ local prev = ts_utils.get_previous_node(node, false, false)
+ if (node.type(prev) == 'comment') then
+ comment = ts_utils.get_node_text(prev)[1]
+ end
+ -- print(vim.inspect(node.type(prev)))
+ -- print(vim.inspect(ts_utils.get_node_text(prev)))
+ end
+
+ print(vim.inspect(comment))
+ -- if type_list is not present could go up and read the comment
+ -- and base on a regular expression, and get the type
+ -- if the type is array want to also read to see if is a typed array
+ --
+ local classNode = node.parent()
+
+
+
+ vim.api.nvim_buf_set_lines(bufnr, )
+
+end
+
+return M
diff --git a/lua/alpha/telescope.lua b/lua/alpha/telescope.lua
index 6bb4150..310504b 100644
--- a/lua/alpha/telescope.lua
+++ b/lua/alpha/telescope.lua
@@ -1,4 +1,5 @@
local actions = require('telescope.actions')
+
require('telescope').setup {
defaults = {
file_sorter = require('telescope.sorters').get_fzy_sorter,
@@ -48,4 +49,14 @@ M.branches = function()
end})
end
+-- just a test base on a relative path
+M.laravel_controllers = function()
+ require("telescope.builtin").find_files({
+ prompt_title = "< Controllers >",
+ cwd = "app/Http/Controllers",
+ })
+end
+
+M.laravel_artisan = require('alpha.telescope_laravel').artisan
+
return M
diff --git a/lua/alpha/telescope_laravel.lua b/lua/alpha/telescope_laravel.lua
new file mode 100644
index 0000000..1e4fa28
--- /dev/null
+++ b/lua/alpha/telescope_laravel.lua
@@ -0,0 +1,77 @@
+local actions = require('telescope.actions')
+local pickers = require "telescope.pickers"
+local finders = require "telescope.finders"
+local previewers = require "telescope.previewers"
+local conf = require("telescope.config").values
+local putils = require "telescope.previewers.utils"
+local action_state = require "telescope.actions.state"
+local utils = require "telescope.utils"
+local laravel = {}
+
+function Split(s, delimiter)
+ local result = {};
+ for match in (s..delimiter):gmatch("(.-)"..delimiter) do
+ table.insert(result, match);
+ end
+ return result;
+end
+
+local lookup_keys = {
+ display = 1,
+ ordinal = 1,
+ value = 1,
+}
+
+local mt_string_entry = {
+ __index = function(t, k)
+ return rawget(t, rawget(lookup_keys, k))
+ end,
+}
+
+laravel.artisan = function(opts)
+
+ local results = utils.get_os_command_output({
+ "php",
+ "artisan",
+ "--raw",
+ }, opts.cwd)
+
+ pickers.new(opts, {
+ prompt_title = "Artisan commands",
+ finder = finders.new_table {
+ results = results,
+ entry_maker = function (line)
+ return setmetatable({
+ Split(line, " ")[1],
+ }, mt_string_entry)
+ end
+ },
+ previewer = previewers.new_buffer_previewer {
+ title = "Help",
+ get_buffer_by_name = function(_, entry)
+ return entry.value
+ end,
+
+ define_preview = function(self, entry)
+
+ local cmd = { "php", "artisan", entry.value, "-h" }
+
+ putils.job_maker(cmd, self.state.bufnr, {
+ value = entry.value,
+ bufname = self.state.bufname,
+ })
+ end,
+ },
+ sorter = conf.file_sorter(opts),
+ attach_mappings = function (_, map)
+ map('i', '<cr>', function(prompt_bufnr)
+ local entry = action_state.get_selected_entry()
+ actions.close(prompt_bufnr)
+ vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(":Artisan " .. entry.value, true, false, true), "t", true)
+ end)
+ return true
+ end
+ }):find()
+end
+
+return laravel