aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha
diff options
context:
space:
mode:
authorAriel D'Alessandro <ariel.dalessandro@auto1.com>2021-10-11 09:50:14 +0200
committerAriel D'Alessandro <ariel.dalessandro@auto1.com>2021-10-11 09:50:14 +0200
commite019b5a3213e078358bdce1d098ec9eb939f16a8 (patch)
tree978048ea2926c5fcae2c4abb93f02e78045335a8 /lua/alpha
parent10b83cc1dbf6c7562b1bdf26cdfda8876600a17f (diff)
downloadnvim-conf-e019b5a3213e078358bdce1d098ec9eb939f16a8.tar.gz
nvim-conf-e019b5a3213e078358bdce1d098ec9eb939f16a8.zip
Improvements
Diffstat (limited to 'lua/alpha')
-rw-r--r--lua/alpha/refactor.lua45
1 files changed, 43 insertions, 2 deletions
diff --git a/lua/alpha/refactor.lua b/lua/alpha/refactor.lua
index d4cea4e..1d89fad 100644
--- a/lua/alpha/refactor.lua
+++ b/lua/alpha/refactor.lua
@@ -50,8 +50,9 @@ M.setter_getter = function()
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]
- comment = string.match(comment, '@var (.*) ')
+ comment = ts_utils.get_node_text(prev)[2]
+ -- print(vim.inspect(comment))
+ comment = string.match(comment, '@var (.*)')
end
-- print(vim.inspect(node.type(prev)))
-- print(vim.inspect(ts_utils.get_node_text(prev)))
@@ -71,7 +72,47 @@ M.setter_getter = function()
return (str:gsub("^%l", string.upper))
end
+ local function mysplit (inputstr, sep)
+ if sep == nil then
+ sep = "%s"
+ end
+ local t={}
+ for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
+ table.insert(t, str)
+ end
+ return t
+ end
+
+ local function implode(delimiter, list)
+ local len = #list
+ if len == 0 then
+ return ""
+ end
+ local string = list[1]
+ for i = 2, len do
+ string = string .. delimiter .. list[i]
+ end
+ return string
+ end
+
local varType = p.type_list
+ if (varType == nil) then
+ local isNullable = false
+ local types = {}
+ local commentTypes = mysplit(comment, "|")
+ for _, v in ipairs(commentTypes) do
+ if (v == "null") then
+ isNullable = true
+ else
+ table.insert(types, v)
+ end
+ end
+ varType = implode("|", types)
+ if (isNullable) then
+ varType = "?" .. varType
+ end
+
+ end
local insert = {}
table.insert(insert, "")