local ls = require("luasnip") local fmt = require('luasnip.extras.fmt').fmt local s = ls.s local sn = ls.sn local t = ls.text_node local f = ls.function_node local i = ls.insert_node local c = ls.choice_node local exec = function(command) return f(function(_, _, arg) local p = io.popen(arg, 'r') local res = {} for line in p:lines() do table.insert(res, line) end return res end, {}, { user_args = { command }}) end local calculate_commentstring = require('Comment.ft').calculate local get_region = require('Comment.utils').get_region ---@param ctype number|(ex.: 1 (line), 2 (block)) local comment = function(ctype, inner) local get_cstring = function() local cs = calculate_commentstring({ ctype = ctype, range = get_region() }) or '' local tbl = vim.split(cs, '%s', {plain = true, trimempty = true}) return (#tbl == 0) and {'', ''} or ((#tbl == 1) and {tbl[1], ''} or {tbl[1], tbl[2]}) end return sn(nil, { f(function() return get_cstring()[1] end), t(' '), inner, f(function() return get_cstring()[2] end), }) end -- snipmate snippets -- require('luasnip.loaders.from_snipmate').load({ paths = {'~/.config/nvim/after/snippets'} }) ls.add_snippets('all', { s('sign', t('Robert Günzler ')), s('me', fmt( [[{} <{}>]], { exec('git config --get user.name'), exec('git config --get user.email'), } ) ), }, { type = 'snippets', key = 'signature_helpers'}) ls.add_snippets('all', { s('today', f(function() return os.date('%Y-%m-%d') end, {})), s('now', f(function() return os.date('%Y-%m-%dT%H:%M:%SZ') end, {})) }, { type = 'snippets', key = 'date_helpers'}) ls.add_snippets('all', { s({ trig = 'todo', docstring = 'TODO:' }, comment(1, fmt([[{}: ]], { t('TODO') }))), -- s({ trig = 'todo', docstring = '{1:TODO}: {2}' }, comment(1, fmt([[{}: {}]], { c(1, {t('TODO')}), i(2) }))), -- s('note', comment(1, fmt([[NOTE: {}]], { i(0) }))), -- s('hack', comment(1, fmt([[HACK: {}]], { i(0) }))), -- s('warn', comment(1, fmt([[{}: {}]], { -- c(1, {t('WARN'), t('WARNING'), t('XXX')}), -- i(0), -- }))), -- s('fix', comment(1, fmt([[{}: {}]], { -- c(1, {t('FIX'), t('FIXME'), t('ISSUE'), t('BUG')}), -- i(0), -- }))), }, { type = 'snippets', key = 'todo_comments'})