Update snippets
This commit is contained in:
@@ -1,84 +1,100 @@
|
|||||||
local ls = require("luasnip")
|
local ls = require 'luasnip'
|
||||||
local s = ls.snippet
|
local s = ls.snippet
|
||||||
local t = ls.text_node
|
local t = ls.text_node
|
||||||
local i = ls.insert_node
|
local i = ls.insert_node
|
||||||
local f = ls.function_node
|
local f = ls.function_node
|
||||||
|
|
||||||
local function psr_namespace(args, snip)
|
local function psr_namespace(args, snip)
|
||||||
local path = snip.env.TM_FILENAME_FULL or ""
|
local path = snip.env.TM_FILENAME_FULL or ''
|
||||||
local root = "/src/"
|
local root = '/src/'
|
||||||
local ns = path:match(root .. "(.*)/[^/]+%.php$")
|
local ns = path:match(root .. '(.*)/[^/]+%.php$')
|
||||||
if ns then
|
if ns then
|
||||||
return ns:gsub("/", "\\")
|
return ns:gsub('/', '\\')
|
||||||
else
|
else
|
||||||
return "App"
|
return 'App'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function class_name(args, snip)
|
local function class_name(args, snip)
|
||||||
local filename = snip.env.TM_FILENAME or ""
|
local filename = snip.env.TM_FILENAME or ''
|
||||||
return filename:match("([^%.]+)") or "ClassName"
|
return filename:match '([^%.]+)' or 'ClassName'
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
s("du", { t("dump("), i(1), t(");") }),
|
s('du', { t 'dump(', i(0), t ');' }),
|
||||||
s("dt", { t("\\PhpStan\\dumpType("), i(1), t(");") }),
|
s('dt', { t '\\PhpStan\\dumpType(', i(0), t ');' }),
|
||||||
s("ql", {
|
s('ql', {
|
||||||
t("\\Illuminate\\Support\\Facades\\DB::listen(function (\\Illuminate\\Database\\Events\\QueryExecuted $e) {"),
|
t '\\Illuminate\\Support\\Facades\\DB::listen(function (\\Illuminate\\Database\\Events\\QueryExecuted $e) {',
|
||||||
t({"", " dump($e->sql, $e->bindings);"}),
|
t { '', ' dump($e->sql, $e->bindings);' },
|
||||||
t({"", "});"})
|
t { '', '});' },
|
||||||
}),
|
}),
|
||||||
s("test", {
|
s('test', {
|
||||||
t("test("), i(1), t(", function () {"),
|
t 'test(',
|
||||||
t({"", " "}), i(2),
|
i(1),
|
||||||
t({"", ");"})
|
t ', function () {',
|
||||||
|
t { '', ' ' },
|
||||||
|
i(0),
|
||||||
|
t { '', ');' },
|
||||||
}),
|
}),
|
||||||
s("/**", {
|
s('/**', {
|
||||||
t("/**"),
|
t '/**',
|
||||||
t({"", " * "}), i(1),
|
t { '', ' * ' },
|
||||||
t({"", " */"})
|
i(0),
|
||||||
|
t { '', ' */' },
|
||||||
}),
|
}),
|
||||||
s("@p", { t("@property "), i(1), t(" $"), i(2) }),
|
s('@p', { t '@property ', i(1), t ' $', i(0) }),
|
||||||
s("@pb", { t("@property bool $"), i(1) }),
|
s('@pb', { t '@property bool $', i(0) }),
|
||||||
s("@ps", { t("@property string $"), i(1) }),
|
s('@ps', { t '@property string $', i(0) }),
|
||||||
s("@pi", { t("@property int $"), i(1) }),
|
s('@pi', { t '@property int $', i(0) }),
|
||||||
s("@pc", { t("@property \\Illuminate\\Support\\Collection<int, "), i(1), t("> $"), i(2) }),
|
s('@pc', { t '@property \\Illuminate\\Support\\Collection<int, ', i(1), t '> $', i(0) }),
|
||||||
s("@pd", { t("@property \\Illuminate\\Support\\Carbon $"), i(1) }),
|
s('@pd', { t '@property \\Illuminate\\Support\\Carbon $', i(0) }),
|
||||||
s("@pp", {
|
s('@pp', {
|
||||||
t("/**"),
|
t '/**',
|
||||||
t({"", " * @property int $id"}),
|
t { '', ' * @property int $id' },
|
||||||
t({"", " * "}), i(1),
|
t { '', ' * ' },
|
||||||
t({"", " * @property \\Illuminate\\Support\\Carbon $created_at"}),
|
i(1),
|
||||||
t({"", " * @property \\Illuminate\\Support\\Carbon $updated_at"}),
|
t { '', ' * @property \\Illuminate\\Support\\Carbon $created_at' },
|
||||||
t({"", " *", " * Relationships"}),
|
t { '', ' * @property \\Illuminate\\Support\\Carbon $updated_at' },
|
||||||
t({"", " * "}), i(2),
|
t { '', ' *', ' * Relationships' },
|
||||||
t({"", " */"})
|
t { '', ' * ' },
|
||||||
|
i(0),
|
||||||
|
t { '', ' */' },
|
||||||
}),
|
}),
|
||||||
s("php", {
|
s('php', {
|
||||||
t("<?php"),
|
t '<?php',
|
||||||
t({"", ""}),
|
t { '', '' },
|
||||||
t("namespace "),
|
t 'namespace ',
|
||||||
f(psr_namespace, {}),
|
f(psr_namespace, {}),
|
||||||
t(";"),
|
t ';',
|
||||||
t({"", "", "/**", " * Class "}),
|
t { '', '', '/**', ' * Class ' },
|
||||||
f(class_name, {}),
|
f(class_name, {}),
|
||||||
t({"", " */", "class "}),
|
t { '', ' */', 'class ' },
|
||||||
f(class_name, {}),
|
f(class_name, {}),
|
||||||
i(1),
|
i(1),
|
||||||
t({"", "{", " public function __construct()", " {", " "}),
|
t { '', '{', ' public function __construct()', ' {', ' ' },
|
||||||
i(2, "// TODO: Implement constructor"),
|
i(0, '// TODO: Implement constructor'),
|
||||||
t({"", " }", "}"})
|
t { '', ' }', '}' },
|
||||||
}),
|
}),
|
||||||
s("pub", {
|
s('pub', {
|
||||||
t("public function "), i(1), t("("), i(2), t(")"),
|
t 'public function ',
|
||||||
t({"", "{"}),
|
i(1),
|
||||||
t({"", " "}), i(3),
|
t '(',
|
||||||
t({"", "}"})
|
i(2),
|
||||||
|
t ')',
|
||||||
|
t { '', '{' },
|
||||||
|
t { '', ' ' },
|
||||||
|
i(0),
|
||||||
|
t { '', '}' },
|
||||||
}),
|
}),
|
||||||
s("pro", {
|
s('pro', {
|
||||||
t("protected function "), i(1), t("("), i(2), t(")"),
|
t 'protected function ',
|
||||||
t({"", "{"}),
|
i(1),
|
||||||
t({"", " "}), i(3),
|
t '(',
|
||||||
t({"", "}"})
|
i(2),
|
||||||
|
t ')',
|
||||||
|
t { '', '{' },
|
||||||
|
t { '', ' ' },
|
||||||
|
i(0),
|
||||||
|
t { '', '}' },
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user