diff options
| author | Ariel D'Alessandro <ariel.dalessandro@auto1.com> | 2021-09-07 08:01:44 +0200 |
|---|---|---|
| committer | Ariel D'Alessandro <ariel.dalessandro@auto1.com> | 2021-09-07 08:01:44 +0200 |
| commit | b8d7f83d8b902b136ea505bbe21a17cc4958087a (patch) | |
| tree | 4e253f73cb02676f23ba0656609f82543e4affbd /lua | |
| parent | 3706c4f276cb17ef9f810a3348e7566d92415e55 (diff) | |
| parent | 7d3824bb003a52eae168e45c616b168a9fd4ecdf (diff) | |
| download | nvim-conf-b8d7f83d8b902b136ea505bbe21a17cc4958087a.tar.gz nvim-conf-b8d7f83d8b902b136ea505bbe21a17cc4958087a.zip | |
Merge branch 'main' of github.com:adalessa/dotfiles
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/alpha/init.lua | 1 | ||||
| -rw-r--r-- | lua/alpha/refactor.lua | 43 | ||||
| -rw-r--r-- | lua/alpha/snippets.lua | 6 |
3 files changed, 42 insertions, 8 deletions
diff --git a/lua/alpha/init.lua b/lua/alpha/init.lua index 3d3ce78..bc869ec 100644 --- a/lua/alpha/init.lua +++ b/lua/alpha/init.lua @@ -2,3 +2,4 @@ require("alpha.telescope") require("alpha.refactoring") require("alpha.snippets") require("alpha.harpoon") +require("alpha.refactor") diff --git a/lua/alpha/refactor.lua b/lua/alpha/refactor.lua index dbf4c5f..d4cea4e 100644 --- a/lua/alpha/refactor.lua +++ b/lua/alpha/refactor.lua @@ -43,7 +43,7 @@ M.setter_getter = function() -- visibility modifier -- type_list (optional) could have a ? to be nullable or could have a list -- property_element - print(vim.inspect(p)) + -- print(vim.inspect(p)) local comment = '' @@ -51,21 +51,56 @@ M.setter_getter = function() local prev = ts_utils.get_previous_node(node, false, false) if (node.type(prev) == 'comment') then comment = ts_utils.get_node_text(prev)[1] + comment = string.match(comment, '@var (.*) ') end -- print(vim.inspect(node.type(prev))) -- print(vim.inspect(ts_utils.get_node_text(prev))) end - print(vim.inspect(comment)) + -- 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() + local classNode = node:parent() + local classEnd = classNode:end_() + local variable = string.sub(p.property_element, 2) + local function firstToUpper(str) + return (str:gsub("^%l", string.upper)) + end + + local varType = p.type_list - vim.api.nvim_buf_set_lines(bufnr, ) + local insert = {} + table.insert(insert, "") + if (comment ~= nil) then + table.insert(insert, " /**") + table.insert(insert, string.format("\t * @return %s", comment)) + table.insert(insert, " */") + end + table.insert(insert, string.format("\tpublic function get%s(): %s", firstToUpper(variable), varType)) + table.insert(insert, " {") + table.insert(insert, string.format("\t\treturn $this->%s;", variable)) + table.insert(insert, " }") + table.insert(insert, "") + + if (comment ~= nil) then + table.insert(insert, " /**") + table.insert(insert, string.format("\t * @param %s %s", comment, p.property_element)) + table.insert(insert, " *") + table.insert(insert, " * @return self") + table.insert(insert, " */") + end + table.insert(insert, string.format("\tpublic function set%s(%s %s): self", firstToUpper(variable), varType, p.property_element)) + table.insert(insert, " {") + table.insert(insert, string.format("\t\t$this->%s = %s;", variable, p.property_element)) + table.insert(insert, "") + table.insert(insert, string.format("\t\treturn $this;")) + table.insert(insert, " }") + + vim.api.nvim_buf_set_lines(bufnr, classEnd, classEnd, false, insert) end diff --git a/lua/alpha/snippets.lua b/lua/alpha/snippets.lua index 378fa20..9a42b6c 100644 --- a/lua/alpha/snippets.lua +++ b/lua/alpha/snippets.lua @@ -9,10 +9,8 @@ local d = ls.dynamic_node ls.snippets = { php = { - s("getter", { - t("/**"), - t(" *"), - t(" *"), + s("$", { + t("$this->"), }) } } |