aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorAriel D'Alessandro <dalessandro.ariel@gmail.com>2022-02-12 21:07:15 +0100
committerAriel D'Alessandro <dalessandro.ariel@gmail.com>2022-02-12 21:07:15 +0100
commit535b2236a134a4e36979ae27159c3f46e808ca6c (patch)
tree5e26a0ae61525177311acbb6b24e37a1eea3744d /lua
parentff4c5962014c0b0c49da786536bba0cd16dfe10a (diff)
downloadnvim-conf-535b2236a134a4e36979ae27159c3f46e808ca6c.tar.gz
nvim-conf-535b2236a134a4e36979ae27159c3f46e808ca6c.zip
improve snippets
Diffstat (limited to 'lua')
-rw-r--r--lua/alpha/snips/ft/go.lua3
-rw-r--r--lua/alpha/snips/ft/lua.lua46
-rw-r--r--lua/alpha/snips/ft/php.lua110
3 files changed, 159 insertions, 0 deletions
diff --git a/lua/alpha/snips/ft/go.lua b/lua/alpha/snips/ft/go.lua
new file mode 100644
index 0000000..5044d6f
--- /dev/null
+++ b/lua/alpha/snips/ft/go.lua
@@ -0,0 +1,3 @@
+local M = {}
+
+return M
diff --git a/lua/alpha/snips/ft/lua.lua b/lua/alpha/snips/ft/lua.lua
new file mode 100644
index 0000000..539751e
--- /dev/null
+++ b/lua/alpha/snips/ft/lua.lua
@@ -0,0 +1,46 @@
+local ls = require "luasnip"
+
+-- local snippet = ls.s
+local snippet_from_nodes = ls.sn
+local c = ls.choice_node
+local d = ls.dynamic_node
+local i = ls.insert_node
+local t = ls.text_node
+
+local fmt = require("luasnip.extras.fmt").fmt
+
+local require_var = function(args, _)
+ local text = args[1][1] or ""
+ local split = vim.split(text, ".", { plain = true })
+
+ local options = {}
+ for len = 0, #split - 1 do
+ table.insert(options, t(table.concat(vim.list_slice(split, #split - len, #split), "_")))
+ end
+
+ return snippet_from_nodes(nil, {
+ c(1, options),
+ })
+end
+
+local newline = function(text)
+ return t { "", text }
+end
+
+return {
+ req = fmt([[local {} = require("{}")]], {
+ d(2, require_var, { 1 }),
+ i(1),
+ }),
+ lf = {
+ desc = "table function",
+ "local ",
+ i(1),
+ " = function(",
+ i(2),
+ ")",
+ newline " ",
+ i(0),
+ newline "end",
+ },
+}
diff --git a/lua/alpha/snips/ft/php.lua b/lua/alpha/snips/ft/php.lua
new file mode 100644
index 0000000..c2210a9
--- /dev/null
+++ b/lua/alpha/snips/ft/php.lua
@@ -0,0 +1,110 @@
+local ls = require("luasnip")
+
+local snippet_from_nodes = ls.sn
+local c = ls.choice_node
+local t = ls.text_node
+local d = ls.dynamic_node
+local f = ls.function_node
+local i = ls.insert_node
+local fmt = require("luasnip.extras.fmt").fmt
+
+
+function string.starts(String,Start)
+ return string.sub(String,1,string.len(Start))==Start
+end
+
+local newline = function(text)
+ return t { "", text }
+end
+
+local visibility = function(_, _, _, inital)
+ local possibles = {'private', 'public', 'protected'}
+
+ local options = {}
+
+ for _, value in pairs(possibles) do
+ if value == inital then
+ table.insert(options, 1, t(value))
+ else
+ table.insert(options, t(value))
+ end
+ end
+
+ return snippet_from_nodes(nil, {
+ c(1, options)
+ })
+end
+
+local promoted_property
+promoted_property = function()
+ return snippet_from_nodes(nil, {
+ c(1, {
+ t(""),
+ snippet_from_nodes(nil, {
+ newline "\t",
+ d(1, visibility, {}, "private"),
+ i(2, '$var'),
+ t ",",
+ d(3, promoted_property, {})
+ }),
+ }),
+ })
+end
+
+local namespace = function ()
+ local dir = vim.fn.expand('%:h')
+ local autoloads = vim.call('composer#query', 'autoload.psr-4')
+ if autoloads == nil then
+ return (dir:gsub("^%l", string.upper))
+ end
+
+ local globalNamespace
+ for key, value in pairs(autoloads) do
+ if string.starts(dir, value:sub(1, -2)) then
+ globalNamespace = key:sub(1, -2);
+ dir = dir:sub(#key + 1)
+ break
+ end
+ end
+ dir = dir:gsub("/", "\\")
+
+ return string.format("%s\\%s",globalNamespace, dir )
+end
+
+local class_name = function ()
+ local filename = vim.fn.expand('%:t:r')
+ return filename
+end
+local M = {
+ v = fmt(
+[[
+/**
+ * @var {}
+ */
+{} ${};
+]], {
+ i(1, "type"),
+ d(2, visibility, { 1 }, "private"),
+ i(3, "var")
+ }),
+ class = fmt(
+[[
+<?php
+
+declare(strict_types=1);
+
+namespace [];
+
+class []
+{
+ []
+}
+]],
+ {
+ f(namespace),
+ f(class_name),
+ i(0),
+ }, { delimiters = "[]"}),
+}
+
+return M