diff options
| author | Ariel D'ALessandro <dalessandro.ariel@gmail.com> | 2021-08-22 18:57:16 +0200 |
|---|---|---|
| committer | Ariel D'ALessandro <dalessandro.ariel@gmail.com> | 2021-08-22 18:57:16 +0200 |
| commit | 450c8d49b7d4843cbd6af566eafb98693a2d2fda (patch) | |
| tree | 8927c842bb64773291a5e7bc58f9d3ebb5dc3181 /lua/alpha/refactor.lua | |
| parent | 2f65f4524a084967572dce8277098ff71555b740 (diff) | |
| download | nvim-conf-450c8d49b7d4843cbd6af566eafb98693a2d2fda.tar.gz nvim-conf-450c8d49b7d4843cbd6af566eafb98693a2d2fda.zip | |
add new telecope funcions and add hide bar to tmux
Diffstat (limited to 'lua/alpha/refactor.lua')
| -rw-r--r-- | lua/alpha/refactor.lua | 72 |
1 files changed, 72 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 |