diff --git a/lua/config/luasnip.lua b/lua/config/luasnip.lua index 1e1e3f6..0b55749 100644 --- a/lua/config/luasnip.lua +++ b/lua/config/luasnip.lua @@ -2,10 +2,11 @@ local ls = require("luasnip") local capture = require("utils.capture") local s = ls.snippet local sn = ls.snippet_node +local fmt = require("luasnip.extras.fmt").fmt local t = ls.text_node local i = ls.insert_node local f = ls.function_node -local choice = ls.choice_node +local c = ls.choice_node local d = ls.dynamic_node local function getCurrentYear() @@ -20,6 +21,18 @@ local function getGitUsername() return stdout end +ls.config.set_config { + history = true, + updateevents = "TextChanged,TextChangedI", + enable_autosnippets = true +} + +vim.keymap.set({"i"}, "", function() + if ls.choice_active() then + ls.change_choice(1) + end +end) + ls.add_snippets("all", { s("MIT", { t({"The MIT License (MIT)", "Copyright © "}), @@ -53,3 +66,15 @@ ls.add_snippets("all", { } }) }) + +ls.add_snippets("lua", { + s("req", + fmt([[local {} = require("{}")]], { + f(function(module_name) + local parts = vim.split(module_name[1][1], ".", true) + return (parts[#parts] or ""):gsub("-", "_") + end, { 1 }), + i(1) + }) + ) +})