add snippets for common languages
This commit is contained in:
@@ -9,15 +9,24 @@ return {
|
||||
build = "make install_jsregexp",
|
||||
config = function()
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
|
||||
ls.add_snippets("lua", {
|
||||
s("hello", {
|
||||
t('print("hello world!")'),
|
||||
}),
|
||||
})
|
||||
local snippets_folder = vim.fn.stdpath("config") .. "/snippets"
|
||||
local function load_snippets()
|
||||
-- Load all Lua files in the snippets directory except init.lua
|
||||
local files = vim.fn.glob(snippets_folder .. "/*.lua", false, true)
|
||||
for _, file in ipairs(files) do
|
||||
local filename = vim.fn.fnamemodify(file, ":t")
|
||||
-- Remove .lua extension to get the filetype
|
||||
local ft = filename:match("(.+)%.lua$")
|
||||
if ft then
|
||||
-- Load the file which should return a table of snippets
|
||||
local ok, snippets = pcall(dofile, file)
|
||||
if ok and type(snippets) == "table" then
|
||||
ls.add_snippets(ft, snippets)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
load_snippets()
|
||||
end,
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user