aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha/setter_getter_template.lua
diff options
context:
space:
mode:
authorAriel D'Alessandro <ariel.dalessandro@auto1.com>2022-07-08 10:57:43 +0200
committerAriel D'Alessandro <ariel.dalessandro@auto1.com>2022-07-08 17:07:57 +0200
commitafd9b1b96861f1148b34f2007ec33fab9b6e2190 (patch)
tree0640f259165657272fb88353dad9ba17d00a1a61 /lua/alpha/setter_getter_template.lua
parentbd40e7372cadf3d1dff86e0aaebda9e07281180b (diff)
downloadnvim-conf-afd9b1b96861f1148b34f2007ec33fab9b6e2190.tar.gz
nvim-conf-afd9b1b96861f1148b34f2007ec33fab9b6e2190.zip
Fix some stuffs, code action fix problem with query
Diffstat (limited to 'lua/alpha/setter_getter_template.lua')
-rw-r--r--lua/alpha/setter_getter_template.lua69
1 files changed, 55 insertions, 14 deletions
diff --git a/lua/alpha/setter_getter_template.lua b/lua/alpha/setter_getter_template.lua
index f4a6f81..fc2099f 100644
--- a/lua/alpha/setter_getter_template.lua
+++ b/lua/alpha/setter_getter_template.lua
@@ -10,8 +10,22 @@ local function isNullable(nullable)
return ""
end
+local function getReturnTypes(nullable, types) if #types > 0 then
+ return string.format(": %s%s", isNullable(nullable), table.concat(types, "|"))
+ end
+ return ""
+end
+
+local function getTypeHint(nullable, types) if #types > 0 then
+ return string.format("%s%s ", isNullable(nullable), table.concat(types, "|"))
+ end
+ return ""
+end
+
+
local function toTable(fn)
local t = {}
+ -- todo check why removes all lines
for s in fn:gmatch("[^\r\n]+") do
table.insert(t, s)
end
@@ -19,40 +33,67 @@ local function toTable(fn)
return t
end
-M.getGetter = function(property, nullable, types)
- local fn = string.format([[
- public function get%s(): %s%s
+M.getGetter = function(property, nullable, types, have_dock_block)
+ local comment = ""
+ if have_dock_block and #types > 0 then
+ comment = string.format(
+ [[
+ /**
+ * @return %s
+ */
+]],
+ table.concat(types, "|")
+ )
+ end
+
+ local fn = string.format(
+ [[
+ public function get%s()%s
{
return $this->%s;
}
- ]],
+ ]] ,
utils.ucfirst(property),
- isNullable(nullable),
- table.concat(types, "|"),
+ getReturnTypes(nullable, types),
property
)
- return toTable(fn)
+ return toTable(comment .. fn)
end
-M.getSetter = function(property, nullable, types)
- local fn = string.format([[
- public function set%s(%s%s $%s): self
+M.getSetter = function(property, nullable, types, have_dock_block)
+
+ local comment = ""
+ if have_dock_block and #types > 0 then
+ comment = string.format(
+ [[
+ /**
+ * @param %s $%s
+ *
+ * @return self
+ */
+]],
+ table.concat(types, "|"),
+ property
+ )
+ end
+ local fn = string.format(
+ [[
+ public function set%s(%s$%s): self
{
$this->%s = $%s;
return $this;
}
- ]],
+ ]] ,
utils.ucfirst(property),
- isNullable(nullable),
- table.concat(types, "|"),
+ getTypeHint(nullable, types),
property,
property,
property
)
- return toTable(fn)
+ return toTable(comment .. fn)
end
return M