Skip to content

Commit

Permalink
feat!: Rework Luasnip configuration
Browse files Browse the repository at this point in the history
1. Migrate all snippets to VSC style because my snippets weren't that
complex and didn't utilize the power of Luasnip's snippet engine.
2. Due to 1. clean up and simplify plugin configuration.
3. Provide the possibility to overwrite the snippets folder path.
  • Loading branch information
Allaman committed Jan 9, 2025
1 parent 222904d commit 112028b
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 305 deletions.
61 changes: 16 additions & 45 deletions lua/vnext/plugins/snippets.lua
Original file line number Diff line number Diff line change
@@ -1,58 +1,30 @@
return {
{
"L3MON4D3/LuaSnip",
event = "InsertEnter",
lazy = true,
dependencies = {
{
"rafamadriz/friendly-snippets",
config = function(_, opts)
require("luasnip").filetype_extend("all", { "loremipsum" })
config = function()
require("luasnip.loaders.from_vscode").lazy_load() -- load friendly-snippets
require("luasnip").filetype_extend("all", { "loremipsum" }) -- load loremipsum snippets from friendly-snippets
end,
},
},
build = "make install_jsregexp",
config = function()
local ls = require("luasnip")
local vsc = require("luasnip.loaders.from_vscode")
local lua = require("luasnip.loaders.from_lua")

snip_env = {
s = require("luasnip.nodes.snippet").S,
sn = require("luasnip.nodes.snippet").SN,
t = require("luasnip.nodes.textNode").T,
f = require("luasnip.nodes.functionNode").F,
i = require("luasnip.nodes.insertNode").I,
c = require("luasnip.nodes.choiceNode").C,
d = require("luasnip.nodes.dynamicNode").D,
r = require("luasnip.nodes.restoreNode").R,
l = require("luasnip.extras").lambda,
rep = require("luasnip.extras").rep,
p = require("luasnip.extras").partial,
m = require("luasnip.extras").match,
n = require("luasnip.extras").nonempty,
dl = require("luasnip.extras").dynamic_lambda,
fmt = require("luasnip.extras.fmt").fmt,
fmta = require("luasnip.extras.fmt").fmta,
conds = require("luasnip.extras.expand_conditions"),
types = require("luasnip.util.types"),
events = require("luasnip.util.events"),
parse = require("luasnip.util.parser").parse_snippet,
ai = require("luasnip.nodes.absolute_indexer"),
}

ls.config.set_config({ history = true, updateevents = "TextChanged,TextChangedI" })

-- load lua snippets
lua.load({ paths = os.getenv("HOME") .. "/.config/nvim/snippets/" })
-- load friendly-snippets
-- this must be loaded after custom snippets or they get overwritte!
-- https://github.com/L3MON4D3/LuaSnip/blob/b5a72f1fbde545be101fcd10b70bcd51ea4367de/Examples/snippets.lua#L497
vsc.lazy_load()

-- selecting within a list of options.
opts = {
snippets_path = { vim.fn.stdpath("config") .. "/snippets" }, -- can be overwritten with a LazySpec in extra/
history = true,
updateevents = "TextChanged,TextChangedI",
delete_check_events = "TextChanged",
},
config = function(_, opts)
-- load VSC style snippets
require("luasnip.loaders.from_vscode").lazy_load({ paths = opts.snippets_path })
-- selecting within a list of snippet options.
vim.keymap.set("i", "<c-h>", function()
if ls.choice_active() then
ls.change_choice(1)
if require("luasnip").choice_active() then
require("luasnip").change_choice(1)
end
end)
end,
Expand All @@ -61,7 +33,6 @@ return {
-- luasnip integration
{
"saghen/blink.cmp",
optional = true,
opts = {
snippets = {
preset = "luasnip",
Expand Down
42 changes: 42 additions & 0 deletions snippets/all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"Gmail": {
"prefix": "gmail",
"body": "[email protected]",
"description": "Insert your Gmail address"
},
"Rootknecht": {
"prefix": "rootknecht",
"body": "[email protected]",
"description": "Insert the Rootknecht email address"
},
"MFG": {
"prefix": "mfg",
"body": ["Mit freundlichen Grüßen", "Michael Peter"],
"description": "Insert a friendly closing statement"
},
"Sehr Geehrte": {
"prefix": "sehrg",
"body": ["Sehr geehrte Damen und Herren,", "", ""],
"description": "Insert a formal greeting"
},
"Modeline": {
"prefix": "modeline",
"body": "vim: set foldmethod=marker foldmarker={{{,}}} :",
"description": "Insert a Vim modeline for fold settings"
},
"Current Date": {
"prefix": "date",
"body": "${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}",
"description": "Insert the current date in YYYY-MM-DD format"
},
"Current Time": {
"prefix": "time",
"body": "${CURRENT_HOUR}:${CURRENT_MINUTE}",
"description": "Insert the current time in HH:MM format"
},
"ISO Date-Time": {
"prefix": "htime",
"body": "${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}+10:00",
"description": "Insert the current date and time in ISO 8601 format"
}
}
16 changes: 0 additions & 16 deletions snippets/all.lua

This file was deleted.

12 changes: 12 additions & 0 deletions snippets/go.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Println": {
"prefix": "fl",
"body": ["fmt.Println(${1:text})", "${0}"],
"description": "Simple Println Snippet"
},
"Sprintf": {
"prefix": "fs",
"body": ["fmt.Sprintf(\"${1:verbs}\", ${2:args})", "${0}"],
"description": "Simple Sprintf Snippet"
}
}
35 changes: 0 additions & 35 deletions snippets/go.lua

This file was deleted.

23 changes: 23 additions & 0 deletions snippets/json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"Tasks Configuration": {
"prefix": "tasks",
"body": [
"{",
" \"version\": \"2.0.0\",",
" \"tasks\": [",
" {",
" \"label\": \"Test Overseer\",",
" \"type\": \"shell\",",
" \"command\": \"ping -c 4 google.com\",",
" \"group\": \"test\",",
" \"presentation\": {",
" \"reveal\": \"always\",",
" \"panel\": \"new\"",
" }",
" }",
" ]",
"}"
],
"description": "Insert a tasks configuration template"
}
}
31 changes: 0 additions & 31 deletions snippets/json.lua

This file was deleted.

7 changes: 7 additions & 0 deletions snippets/lua.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Pretty Print": {
"prefix": "pp",
"body": ["vim.print(${1:args})"],
"description": "Pretty Print"
}
}
19 changes: 0 additions & 19 deletions snippets/lua.lua

This file was deleted.

76 changes: 76 additions & 0 deletions snippets/markdown.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"GitLab Warning Emoji": {
"prefix": "gitlab_warn",
"body": [":warning: ${1:warning}${0}"],
"description": "Warning emoji for GitLab markdown"
},
"Hugo Image Shortcut": {
"prefix": "hugoimg",
"body": ["{{< img name=\"${1:name}\" lazy=\"${2:true}\" >}}"],
"description": "Insert a Hugo image shortcut"
},
"Hugo TOC": {
"prefix": "hugotoc",
"body": ["{{< toc >}}"],
"description": "Hugo Table of Contents"
},
"Hugo Separator": {
"prefix": "hugosep",
"body": ["<!-- more -->"],
"description": "Insert a separator in Hugo"
},
"Hugo Resource Entry": {
"prefix": "hugores",
"body": ["- name: ${1:name}", " src: ${2:${1}}", " title: ${3:title}"],
"description": "Insert a Hugo resource entry"
},
"Hugo Alert": {
"prefix": "hugoalert",
"body": [
"{{<< alert ${1:opts} >>}}",
"${2:text}",
"{{<< /alert >>}}",
"${0}"
],
"description": "Alert shortcode of Blowfish theme"
},
"LTeX Language": {
"prefix": "ltexLang",
"body": ["<!-- LTeX: language=${1:lang} -->${0}"],
"description": "Overwrite language for LTeX LSP"
},
"Markdown Link": {
"prefix": "link",
"body": ["[${1:text}](${2:url})${0}"],
"description": "Insert a default Markdown link"
},
"Changelog Template": {
"prefix": "chlog",
"body": [
"# Changelog",
"",
"All notable changes to this project will be documented in this file.",
"",
"The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),",
"and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).",
"",
"## [Unreleased]",
"",
"## [1.1.1] - 2023-03-05",
"",
"### Added",
"",
"### Fixed",
"",
"### Changed",
"",
"### Removed",
"",
"[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.1.1...HEAD",
"[0.0.3]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.2...v0.0.3",
"[0.0.2]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.1...v0.0.2",
"[0.0.1]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/v0.0.1"
],
"description": "Keep a changelog template"
}
}
Loading

0 comments on commit 112028b

Please sign in to comment.