diff --git a/lua/custom/luasnip.lua b/lua/custom/luasnip.lua index e6917c7..2c6820f 100644 --- a/lua/custom/luasnip.lua +++ b/lua/custom/luasnip.lua @@ -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 = "", } vim.keymap.set({ "i", "s" }, "", function() diff --git a/lua/custom/snippets/python.lua b/lua/custom/snippets/python.lua index e1a25ec..8540877 100644 --- a/lua/custom/snippets/python.lua +++ b/lua/custom/snippets/python.lua @@ -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" },