Caveat: I don’t use this plugin (yet)
It sounds like you can either assign the snippet (as a Lua object) directly to the snippets
or autosnippets
table, or put JSON snippets in a directory and use lazy_load({paths = '...'}
as you discovered.
Both versions are shown the sample configuration:
-- Define some snippets
require("luasnip").snippets = {
-- Snippets for all filetypes
all = { ... }
-- Snippets for filetype=python
python = { ... }
}
-- Load snippets from JSON files (VSCode syntax)
require("luasnip/loaders/from_vscode").lazy_load({
paths = {
vim.fn.stdpath('config') .. '/snippets',
}
})
You could also do something more sophisticated with the paths
, like finding all snippets/*.json
files anywhere in &runtimepath
:
--[[ Split a string into lines. ]]
local function split_lines(txt)
return vim.fn.split(txt, '\n')
end
--[[ Find files in the runtime path. ]]
local function glob_runtimepath(pattern)
local runtime_path = vim.fn.escape(vim.o.runtimepath, ' ')
local search_result = vim.fn.globpath(runtime_path, pattern)
return split_lines(search_result)
end
require("luasnip/loaders/from_vscode").lazy_load({
paths = glob_runtimepath('snippets/**/*.json')
})