Make some MORE snippets for python

This commit is contained in:
ashalimov 2025-02-02 00:41:42 +03:00
parent 02246c2385
commit 97a0858e33
2 changed files with 40 additions and 5 deletions

View file

@ -4,7 +4,8 @@ local types = require "luasnip.util.types"
ls.config.set_config {
history = true,
updateevents = "TextChanged, TextChangedI",
enable_autosnippets = true
enable_autosnippets = true,
store_selection_keys = "<c-s>",
}
vim.keymap.set({ "i", "s" }, "<c-k>", function()

View file

@ -6,11 +6,38 @@ local ls = require "luasnip"
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local c = ls.choice_node
local f = ls.function_node
local fmt = require("luasnip.extras.fmt").fmt
local fmta = require("luasnip.extras.fmt").fmta
local rep = require("luasnip.extras").rep
ls.add_snippets("python", {
s({ trig = "cmethod", dscr = "Create method or function with test stub" },
fmta(
[[
def <>():
"""<> for performing <>"""
pass
def test_<>_<>():
"""Test for checking correct work of <> <>"""
assert 1 == 2
<>
]],
{
i(1),
c(2, { t "Function", t "Method" }),
i(3),
rep(1),
f(function(args) return string.lower(args[1][1]) end, { 2 }),
rep(1),
f(function(args) return string.lower(args[1][1]) end, { 2 }),
i(0)
}
)
),
s({ trig = "implog", dscr = "Import necessary logging utils" }, {
t({
"import logging",
@ -21,11 +48,18 @@ ls.add_snippets("python", {
s({ trig = "logevent", dscr = "Import necessary logging utils" },
fmt(
[[
_log.error('{}' * 60))
_log.error({})
_log.error('{}' * 60))
_log.{}('{}' * 60))
_log.{}({})
_log.{}('{}' * 60))
]],
{ i(1), i(2), rep(1) }
{
c(1, { t "error", t "warning", t "info" }),
i(2),
rep(1),
i(3),
rep(1),
rep(2)
}
)
),
s({ trig = "pybasetest", dscr = "Create test suite boilerplate" },