feat(nvim): Tweak dc snippet

This commit is contained in:
punkfairie 2024-02-24 12:28:09 -08:00
parent 9f2d50714d
commit 80b53645cb
5 changed files with 32 additions and 4 deletions

View file

@ -1,6 +1,9 @@
return {
{
"L3MON4D3/LuaSnip",
opts = {
store_selection_keys = "<Tab>",
},
config = function(_, opts)
require("luasnip").setup(opts)

View file

@ -7,7 +7,7 @@ local fmt = require("luasnip.extras.fmt").fmt
local fill = require("snippets.helpers").fill
return {
s({ trig = "dc", desc = "divider comment" }, f(fill, {}, { user_args = { "#% -" } })),
s({ trig = "dc", desc = "divider comment" }, f(fill, {}, { user_args = { "#%- " } })),
s({ trig = "#!", desc = "shebang" }, t("#!/usr/bin/env fish")),

View file

@ -0,0 +1,8 @@
local ls = require("luasnip")
local s = ls.snippet
local f = ls.function_node
local helpers = require("snippets.helpers")
return {
s({ trig = "dc", desc = "divider comment" }, f(helpers.fill, {}, { user_args = { "#%- " } })),
}

View file

@ -1,13 +1,22 @@
local ls = require("luasnip")
local sn = ls.snippet_node
local i = ls.insert_node
local M = {}
M.fill = function(_, _, args)
M.fill = function(_, parent, args)
local title = ""
local chars = {}
if #parent.snippet.env.LS_SELECT_RAW > 0 then
title = print(parent.snippet.env.LS_SELECT_RAW) .. " "
end
for str in string.gmatch(args, "([^%%]+)") do
table.insert(chars, str)
end
local snip = chars[1]
local snip = chars[1] .. " " .. title
local _, c = unpack(vim.api.nvim_win_get_cursor(0))
@ -18,4 +27,12 @@ M.fill = function(_, _, args)
return snip
end
M.get_visual = function(_, parent)
if #parent.snippet.env.LS_SELECT_RAW > 0 then
return sn(nil, i(1, parent.snippet.env.LS_SELECT_RAW))
else -- If LS_SELECT_RAW is empty, return a blank insert node
return sn(nil, i(1))
end
end
return M

View file

@ -4,5 +4,5 @@ local f = ls.function_node
local fill = require("snippets.helpers").fill
return {
s({ trig = "dc", desc = "divider comment" }, f(fill, {}, { user_args = { "--% --" } })),
s({ trig = "dc", desc = "divider comment" }, f(fill, {}, { user_args = { "--%-- " } })),
}