aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha/snippets
diff options
context:
space:
mode:
authorAriel D'Alessandro <dalessandro.ariel@gmail.com>2021-11-25 00:05:34 +0100
committerAriel D'Alessandro <dalessandro.ariel@gmail.com>2021-11-25 00:05:59 +0100
commit412f51cd7ad4ce610ecaf13210b52709fb3e0232 (patch)
treebf6475830cc0df42b671bf7ce9a1b33fe70f0e37 /lua/alpha/snippets
parent31efe743072b868d4bb86ed709b85253db0b1f60 (diff)
downloadnvim-conf-412f51cd7ad4ce610ecaf13210b52709fb3e0232.tar.gz
nvim-conf-412f51cd7ad4ce610ecaf13210b52709fb3e0232.zip
Move config to lua. Add laravel snippets
Diffstat (limited to 'lua/alpha/snippets')
-rw-r--r--lua/alpha/snippets/config.lua34
-rw-r--r--lua/alpha/snippets/init.lua1
-rw-r--r--lua/alpha/snippets/php.lua122
3 files changed, 157 insertions, 0 deletions
diff --git a/lua/alpha/snippets/config.lua b/lua/alpha/snippets/config.lua
new file mode 100644
index 0000000..ff438c2
--- /dev/null
+++ b/lua/alpha/snippets/config.lua
@@ -0,0 +1,34 @@
+local ls = require"luasnip"
+local s = ls.snippet
+local sn = ls.snippet_node
+local t = ls.text_node
+local i = ls.insert_node
+local f = ls.function_node
+local c = ls.choice_node
+local d = ls.dynamic_node
+-- local types = require("luasnip.util.types")
+
+-- Every unspecified option will be set to the default.
+ls.config.set_config({
+ history = true,
+ -- Update more often, :h events for more info.
+ updateevents = "TextChanged,TextChangedI",
+ -- ext_opts = {
+ -- [types.choiceNode] = {
+ -- active = {
+ -- virt_text = { { "choiceNode", "Comment" } },
+ -- },
+ -- },
+ -- },
+ -- treesitter-hl has 100, use something higher (default is 200).
+ ext_base_prio = 300,
+ -- minimal increase in priority.
+ ext_prio_increase = 1,
+ enable_autosnippets = true,
+})
+
+-- ls.snippets = {
+-- php = require('alpha.snippets.php')
+-- }
+
+vim.api.nvim_set_keymap("i", "<c-k>", "<Plug>luasnip-expand-or-jump", {})
diff --git a/lua/alpha/snippets/init.lua b/lua/alpha/snippets/init.lua
new file mode 100644
index 0000000..8318486
--- /dev/null
+++ b/lua/alpha/snippets/init.lua
@@ -0,0 +1 @@
+require('alpha.snippets.config')
diff --git a/lua/alpha/snippets/php.lua b/lua/alpha/snippets/php.lua
new file mode 100644
index 0000000..c8c2053
--- /dev/null
+++ b/lua/alpha/snippets/php.lua
@@ -0,0 +1,122 @@
+local ls = require"luasnip"
+local s = ls.snippet
+local sn = ls.snippet_node
+local t = ls.text_node
+local i = ls.insert_node
+local c = ls.choice_node
+local d = ls.dynamic_node
+
+-- visibility allows to reuse it pasing the first option to show for the
+-- snippet
+local visibility
+visibility = function (_, _, _, initial_text)
+ local possibles = {'private', 'public', 'protected'}
+ local options = {}
+
+ for _, value in pairs(possibles) do
+ if value == initial_text then
+ table.insert(options, 1, t(value .. ' ') )
+ else
+ table.insert(options, t(value .. ' '))
+ end
+ end
+
+ return sn(nil, { c(1, options) })
+end
+
+local promo_property
+promo_property = function()
+ return sn(
+ nil,
+ c(1, {
+ -- Order is important, sn(...) first would cause infinite loop of expansion.
+ t(""),
+ sn(nil, {
+ t({ "", "\t" }),
+ d(1, visibility, {}, "private"),
+ i(2, '$var'),
+ t(","),
+ d(3, promo_property, {})
+ }),
+ })
+ )
+end
+
+ls.snippets = {
+ php = {
+ -- variable
+ s("v", {
+ t({ "/**", " * @var " }),
+ i(1, "types"),
+ t({""," */", "private $"}),
+ i(2, "name"),
+ t(";", ""),
+ }),
+
+ -- __construct
+ s("_c", {
+ d(1, visibility, {}),
+ t('function __construct('),
+ c(2, {
+ sn(nil, {
+ i(1, '$var'),
+ t({")", "{", "\t"}),
+ i(2, ''),
+ t({"", "}"}),
+ }),
+ sn(nil, {
+ d(1, promo_property, {}),
+ t({"",") {", "}"}),
+ }),
+ }),
+ }),
+
+ -- function
+ s("fn", {
+ d(1, visibility, {}, "public"),
+ t("function "),
+ i(2, "name"),
+ t("("),
+ i(3, "$arg"),
+ t(")"),
+ c(4, {
+ sn(nil, {
+ t(': '),
+ i(1, "void"),
+ }),
+ t(""),
+ }),
+ t({"", "{", ""}),
+ t("\t"), i(0, ""),
+ t({"", "}"})
+ }),
+
+ -- Route
+ s("ro", {
+ t("Route::"),
+ c(1, {
+ t("get"),
+ t("post"),
+ t("put"),
+ t("view"),
+ }),
+ t("('"),
+ i(2, "uri"),
+ t("', "),
+ c(3, {
+ sn(nil, {
+ t({'function () {', ' '}),
+ i(1, ''),
+ t({'', '});'}),
+ }),
+ sn(nil, {
+ t('['),
+ i(1, 'Controller'),
+ t('::class, \''),
+ i(2, 'method'),
+ t('\']);'),
+ })
+ }),
+ }),
+ }
+}