Update 2025-10-08

update 2025-10-08
This commit is contained in:
2025-10-08 19:54:46 +03:00
parent f7194a919e
commit 517cef14ea
35 changed files with 756 additions and 748 deletions

1
snippets/all.lua Normal file
View File

@@ -0,0 +1 @@
return {}

3
snippets/c.lua Normal file
View File

@@ -0,0 +1,3 @@
---@diagnostic disable: undefined-global
return {}

3
snippets/cmake.lua Normal file
View File

@@ -0,0 +1,3 @@
---@diagnostic disable: undefined-global
return {}

3
snippets/cpp.lua Normal file
View File

@@ -0,0 +1,3 @@
---@diagnostic disable: undefined-global
return {}

55
snippets/lua.lua Normal file
View File

@@ -0,0 +1,55 @@
---@diagnostic disable: undefined-global
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 sn(nil, {
c(1, options),
})
end
return {
s(
"lf",
fmt(
[[
local function {}({})
{}
end{}
]],
{
i(1),
i(2),
i(3),
i(0),
}
)
),
s(
"fn",
fmt(
[[
function({})
{}
end
]],
{
i(1),
i(0),
}
)
),
s(
"req",
fmt([[ local {} = require("{}") ]], {
d(2, require_var, { 1 }),
i(1),
})
),
}

43
snippets/markdown.lua Normal file
View File

@@ -0,0 +1,43 @@
---@diagnostic disable: undefined-global
return {
s(
"ket",
fmt(
[[
|{}angle.r{}
]],
{
i(1),
i(0),
}
)
),
s(
"ket0",
fmt(
[[
|0angle.r
]],
{}
)
),
s(
"ket1",
fmt(
[[
|1angle.r
]],
{}
)
),
s(
"ketp",
fmt(
[[
|Psi angle.r
]],
{}
)
),
}

104
snippets/python.lua Normal file
View File

@@ -0,0 +1,104 @@
---@diagnostic disable: undefined-global
return {
s(
"logger",
fmt(
[[
import logging
logger = logging.getLogger(__name__)
]],
{}
)
),
s(
"dbg",
fmt(
[[
logger.debug({})
]],
{
i(0),
}
)
),
s(
"info",
fmt(
[[
logger.info({})
]],
{
i(0),
}
)
),
s(
"warn",
fmt(
[[
logger.warning({})
]],
{
i(0),
}
)
),
s(
"err",
fmt(
[[
logger.error({})
]],
{
i(0),
}
)
),
s(
"exc",
fmt(
[[
logger.exception({})
]],
{
i(0),
}
)
),
s(
"crit",
fmt(
[[
logger.critical({})
]],
{
i(0),
}
)
),
s(
"fatal",
fmt(
[[
logger.fatal({})
]],
{
i(0),
}
)
),
}, {
s(
"__",
fmta(
[[
__<init>__<>
]],
{
init = i(1),
i(0),
}
)
),
}

233
snippets/rust.lua Normal file
View File

@@ -0,0 +1,233 @@
---@diagnostic disable: undefined-global
local snippets = {
s("p", fmta([[println!("{}", <>)]], { i(0) })),
s(
"modtest",
fmta(
[[
#[cfg(test)]
mod tests {
use super::*;
<>
}
]],
{ i(0) }
)
),
s(
"test",
fmta(
[[
#[test]
fn <name>() {
<body>
}
]],
{
name = i(1),
body = i(0),
}
)
),
s(
"rstest",
fmta(
[[
#[rstest]
#[case(<case>)]
fn <name>(<args>) {
<body>
}
]],
{
name = i(1),
args = i(2),
case = i(3),
body = i(0),
}
)
),
s(
"tmain",
fmt(
[[
#[tokio::main]
async fn main() -> Result<()> {{
{}
}}
]],
{
i(1, "todo!();"),
}
)
),
s(
"dead",
fmt(
[[
#[allow(dead_code)]
]],
{}
)
),
}
local function has_bevy()
local cwd = vim.fn.getcwd()
local cargo_toml = cwd .. "/Cargo.toml"
if vim.fn.filereadable(cargo_toml) == 1 then
local contents = vim.fn.readfile(cargo_toml)
for _, line in ipairs(contents) do
if line:match("^%s*bevy%s*=") or line:find("bevy") and not line:find("bevy%.") then
return true
end
end
end
return false
end
local bevy_snippets = {
s(
"component",
fmta(
[[
#[derive(Debug, Reflect, Component)]
#[reflect(Component)]
pub struct <name><params>
]],
{
name = i(1, "Component"),
params = c(2, {
t(";"),
t("( );"),
t(" { }"),
}),
}
)
),
s(
"event",
fmta(
[[
#[derive(Debug, Event)]
pub struct <name><params>
]],
{
name = i(1, "Event"),
params = c(2, {
t(";"),
t("( );"),
t(" { }"),
}),
}
)
),
s(
"resource",
fmta(
[[
#[derive(Debug, Default, Reflect, Resource)]
#[reflect(Resource)]
pub struct <name><params>
]],
{
name = i(1, "Resource"),
params = c(2, {
t(";"),
t("( );"),
t(" { }"),
}),
}
)
),
s(
"schedule",
fmta(
[[
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ScheduleLabel)]
pub struct <name><params>
]],
{
name = i(1, "Resource"),
params = c(2, {
t(";"),
t("( );"),
t(" { }"),
}),
}
)
),
s(
"state",
fmta(
[[
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, States)]
pub enum <name> {
#[default]
<default>,
<variants>
}
]],
{
name = i(1, "State"),
default = i(2, "Default"),
variants = i(0),
}
)
),
s(
"systemset",
fmta(
[[
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SystemSet)]
pub enum <name> {
<body>
}
]],
{
name = i(1),
body = i(2),
}
)
),
s(
"plugin",
fmta(
[[
use bevy::prelude::*;
pub(super) fn plugin(app: &mut App) {
<body>
}
]],
{
body = i(0),
}
)
),
s(
"query",
fmta(
[[
fn <name>(<args>) {
<body>
}
]],
{
name = i(1, "sytem"),
args = i(2, "args"),
body = i(0),
}
)
),
}
if has_bevy() then
vim.tbl_extend("force", snippets, bevy_snippets)
end
return snippets

33
snippets/typst.lua Normal file
View File

@@ -0,0 +1,33 @@
---@diagnostic disable: undefined-global
return {
s(
{ trig = "([^%s]+)t", name = "Superscript", regTrig = true },
fmta("(<>)^(<>)", {
f(function(_, snip)
return snip.captures[1]
end),
i(0),
})
),
s(
{ trig = "([^%s]+)b", name = "Subscript", regTrig = true },
fmta("(<>)_(<>)", {
f(function(_, snip)
return snip.captures[1]
end),
i(0),
})
),
s(
{ trig = "([^%s]+)r", name = "Root", regTrig = true },
fmta("sqrt(<>)", {
f(function(_, snip)
return snip.captures[1]
end),
})
),
}, { -- autosnippets
s({ trig = "mt", name = "Math Block" }, fmta("$<>$", { i(1) })),
s({ trig = "mmt", name = "Multiline Math Block" }, fmta("$ <> $", { i(1) })),
}