diff options
| author | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2023-01-31 09:44:13 +0100 |
|---|---|---|
| committer | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2023-01-31 09:44:13 +0100 |
| commit | 669561e21073e6efafddda25ba3ace69fb43819e (patch) | |
| tree | f94ebd60ad4cab480b5cbcb7e65dd2060696c339 /lua/alpha/snips/ft/php.lua | |
| parent | 5044c70e9f62cdd06ee91e754423b07c1c18c12d (diff) | |
| download | nvim-conf-669561e21073e6efafddda25ba3ace69fb43819e.tar.gz nvim-conf-669561e21073e6efafddda25ba3ace69fb43819e.zip | |
feat: apply stylua
Diffstat (limited to 'lua/alpha/snips/ft/php.lua')
| -rw-r--r-- | lua/alpha/snips/ft/php.lua | 198 |
1 files changed, 99 insertions, 99 deletions
diff --git a/lua/alpha/snips/ft/php.lua b/lua/alpha/snips/ft/php.lua index d70db2e..abfc6f7 100644 --- a/lua/alpha/snips/ft/php.lua +++ b/lua/alpha/snips/ft/php.lua @@ -1,5 +1,5 @@ -local ls = require("luasnip") -local composer = require("composer") +local ls = require "luasnip" +local composer = require "composer" local snippet_from_nodes = ls.sn local c = ls.choice_node @@ -10,72 +10,72 @@ 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 + return string.sub(String, 1, string.len(Start)) == Start end local newline = function(text) - return t({ "", text }) + return t { "", text } end local visibility = function(position, default) - local possibles = { "private", "protected", "public" } - local options = {} - - for _, value in pairs(possibles) do - if value == default then - table.insert(options, 1, t(value)) - else - table.insert(options, t(value)) - end - end - - return c(position, options) + local possibles = { "private", "protected", "public" } + local options = {} + + for _, value in pairs(possibles) do + if value == default then + table.insert(options, 1, t(value)) + else + table.insert(options, t(value)) + end + end + + return c(position, options) end local namespace = function() - local dir = vim.fn.expand("%:h") - local autoloads = 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("/", "\\") - if dir == "" then - return globalNamespace - end - - return string.format("%s\\%s", globalNamespace, dir) + local dir = vim.fn.expand "%:h" + local autoloads = 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("/", "\\") + if dir == "" then + return globalNamespace + end + + return string.format("%s\\%s", globalNamespace, dir) end local class_name = function() - return vim.fn.expand("%:t:r") + return vim.fn.expand "%:t:r" end local M = {} M.v = fmt( - [[ + [[ /** * @var {} */ {} ${}; ]], - { - i(1, "type"), - visibility(2, "private"), - i(3, "var"), - } + { + i(1, "type"), + visibility(2, "private"), + i(3, "var"), + } ) M.class = fmt( - [[ + [[ <?php declare(strict_types=1); @@ -87,89 +87,89 @@ class {} {} }} ]], - { - f(namespace), - f(class_name), - i(0), - } + { + f(namespace), + f(class_name), + i(0), + } ) M.pro = fmt([[{} {}{} ${},]], { - visibility(1, "private"), - c(2, { - t(""), - t("readonly "), - }), - i(3, "Type"), - d(4, function(args) - return snippet_from_nodes(nil, { - i(1, args[1][1]:gsub("^%u", string.lower) or ""), - }) - end, { 3 }), + visibility(1, "private"), + c(2, { + t "", + t "readonly ", + }), + i(3, "Type"), + d(4, function(args) + return snippet_from_nodes(nil, { + i(1, args[1][1]:gsub("^%u", string.lower) or ""), + }) + end, { 3 }), }) M.arg = fmt([[{} ${}]], { - i(1, "Type"), - d(2, function(args) - return snippet_from_nodes(nil, { - i(1, args[1][1]:gsub("^%u", string.lower) or ""), - }) - end, { 1 }), + i(1, "Type"), + d(2, function(args) + return snippet_from_nodes(nil, { + i(1, args[1][1]:gsub("^%u", string.lower) or ""), + }) + end, { 1 }), }) M._c = fmt( - [[{} function __construct({}) {{ + [[{} function __construct({}) {{ {} }}]], - { - visibility(1, "public"), - i(2), - i(0), - } + { + visibility(1, "public"), + i(2), + i(0), + } ) M._p = fmt( - [[{} function __construct( + [[{} function __construct( {} ) {{ }}]], - { - visibility(1, "public"), - i(2), - } + { + visibility(1, "public"), + i(2), + } ) -M.strict = t("declare(strict_types=1);") +M.strict = t "declare(strict_types=1);" M.fn = { - visibility(1, "public"), - t(" function "), - i(2, "name"), - t("("), - i(3), - t(")"), - c(4, { - t(""), - snippet_from_nodes(nil, { - t(": "), - i(1, "void"), - }), - }), - newline("{"), - newline("\t"), - i(0, ""), - newline("}"), + visibility(1, "public"), + t " function ", + i(2, "name"), + t "(", + i(3), + t ")", + c(4, { + t "", + snippet_from_nodes(nil, { + t ": ", + i(1, "void"), + }), + }), + newline "{", + newline "\t", + i(0, ""), + newline "}", } M["then"] = fmt( - [[->then(function ({}) {{ + [[->then(function ({}) {{ {} }})]], - { i(1, ""), i(2, "") } + { i(1, ""), i(2, "") } ) M.test = fmt( - [[/** + [[/** * @test */ public function it_{}(): void @@ -177,7 +177,7 @@ public function it_{}(): void {} }} ]], - { i(1, ""), i(0, "") } + { i(1, ""), i(0, "") } ) return M |