From 02246c2385cde5ddf68a91c9b6bc13c68ccf6ec7 Mon Sep 17 00:00:00 2001 From: ashalimov Date: Sat, 1 Feb 2025 23:26:39 +0300 Subject: [PATCH] Add some python snippets --- lua/custom/snippets/python.lua | 57 +++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/lua/custom/snippets/python.lua b/lua/custom/snippets/python.lua index eaefb80..e1a25ec 100644 --- a/lua/custom/snippets/python.lua +++ b/lua/custom/snippets/python.lua @@ -1,9 +1,58 @@ -- Clear snippets collection when souring lua file -require("luasnip.session.snippet_collection").clear_snippets "lua" +require("luasnip.session.snippet_collection").clear_snippets "python" local ls = require "luasnip" -ls.add_snippets("lua", { - ls.parser.parse_snippet("expand", "-- this is what was expanded kek"), - ls.parser.parse_snippet("pipa", "Pipasik"), +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node + +local fmt = require("luasnip.extras.fmt").fmt +local rep = require("luasnip.extras").rep + +ls.add_snippets("python", { + s({ trig = "implog", dscr = "Import necessary logging utils" }, { + t({ + "import logging", + "_log = logging.getLogger(__name__)" + } + ) + }), + s({ trig = "logevent", dscr = "Import necessary logging utils" }, + fmt( + [[ + _log.error('{}' * 60)) + _log.error({}) + _log.error('{}' * 60)) + ]], + { i(1), i(2), rep(1) } + ) + ), + s({ trig = "pybasetest", dscr = "Create test suite boilerplate" }, + fmt( + [[ + class Test{}: + """Test suite for checking correct work of {} feature""" + + @pytest.fixture(autouse=True) + def setup_test(self): + """Fixture for initializing test cases base data""" + {} + + {} + ]], + { i(1), rep(1), i(2), i(0) } + ) + ), + s({ trig = "pysection", dscr = "Secion snippet" }, + fmt( + [[ + ##################### Section ############################## + # Section topic: {} + ############################################################ + {} + ]], + { i(1), i(0) } + ) + ), })