diff options
| author | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2021-11-26 23:50:37 +0100 |
|---|---|---|
| committer | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2021-11-27 08:40:07 +0100 |
| commit | 9a4440e28d43ee9de2150f069f1ee4c40b20e729 (patch) | |
| tree | 9cff11ab3d87710482e4a6fcddb32347a9d1d7be /lua/alpha/snippets/php.lua | |
| parent | 159cfbc7718d8590c3a30eabd1047649d1b9941b (diff) | |
| download | nvim-conf-9a4440e28d43ee9de2150f069f1ee4c40b20e729.tar.gz nvim-conf-9a4440e28d43ee9de2150f069f1ee4c40b20e729.zip | |
Small fixes, add new snippet for relations
Diffstat (limited to 'lua/alpha/snippets/php.lua')
| -rw-r--r-- | lua/alpha/snippets/php.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lua/alpha/snippets/php.lua b/lua/alpha/snippets/php.lua index f42ed45..0831aa3 100644 --- a/lua/alpha/snippets/php.lua +++ b/lua/alpha/snippets/php.lua @@ -5,6 +5,8 @@ local t = ls.text_node local i = ls.insert_node local c = ls.choice_node local d = ls.dynamic_node +local f = ls.function_node +local l = require("luasnip.extras").lambda -- visibility allows to reuse it pasing the first option to show for the -- snippet @@ -24,6 +26,19 @@ visibility = function (_, _, _, initial_text) return sn(nil, { c(1, options) }) end +local releation +releation = function (_, snip,_, type) + local relationType = type + local relationName = snip.captures[1] + + return sn(nil, { + -- I would like t o auto import the relation but for now just ommit it + -- t({"public function ".. relationName:gsub("^%u", string.lower) .. "(): " .. relationType:gsub("^%l", string.upper) , "{", ""}), + t({"public function ".. relationName:gsub("^%u", string.lower) .. "()" , "{", ""}), + t({"\treturn $this->".. relationType .. "(".. relationName .. "::class);", "}"}), + }) +end + local promo_property promo_property = function() return sn( @@ -120,3 +135,15 @@ ls.snippets = { }), } } + +local relationTypes = {"hasOne", "belongsTo", "hasMany", "belongsToMany"} +for _, type in pairs(relationTypes) do + table.insert(ls.snippets.php, + s( + { trig= type .. "(.*)", regTrig=true }, + { + d(1, releation, {}, type), + } + ) + ) +end |