Skip to content

Commit

Permalink
Merge pull request #173 from leiserfg/auto-json-snips
Browse files Browse the repository at this point in the history
Add json options (fixes #172)
  • Loading branch information
L3MON4D3 committed Sep 17, 2021
2 parents ada2371 + 60e1074 commit 737a2e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
4 changes: 3 additions & 1 deletion DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ In this case `opts` only accepts paths (`runtimepath` if any). That will load
the general snippets (the ones of filetype 'all') and those of the filetype
of the buffers, you open every time you open a new one (but it won't reload them).


Apart from what is stipulated by the start each snippet in the json file can
contain a "luasnip" field wich is a table for extra parameters for the snippet,
till now the only valid one is autotrigger.

# EXT\_OPTS

Expand Down
4 changes: 4 additions & 0 deletions doc/luasnip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ In this case `opts` only accepts paths (`runtimepath` if any). That will load
the general snippets (the ones of filetype 'all') and those of the filetype
of the buffers, you open every time you open a new one (but it won't reload them).

Apart from what is stipulated by the start each snippet in the json file can
contain a "luasnip" field wich is a table for extra parameters for the snippet,
till now the only valid one is autotrigger.

================================================================================
EXT_OPTS *luasnip-ext_opts*

Expand Down
26 changes: 16 additions & 10 deletions lua/luasnip/loaders/from_vscode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ local function load_snippet_file(langs, snippet_set_path)

for _, lang in pairs(langs) do
local lang_snips = ls.snippets[lang] or {}

local auto_lang_snips = ls.autosnippets[lang] or {}
for name, parts in pairs(snippet_set_data) do
local body = type(parts.body) == "string" and parts.body
or table.concat(parts.body, "\n")
Expand All @@ -81,19 +81,25 @@ local function load_snippet_file(langs, snippet_set_path)
and parts.prefix
or { parts.prefix }
for _, prefix in ipairs(prefixes) do
table.insert(
lang_snips,
ls.parser.parse_snippet({
trig = prefix,
name = name,
dscr = parts.description or name,
wordTrig = true,
}, body)
)
local ls_conf = parts.luasnip or {}

local snip = ls.parser.parse_snippet({
trig = prefix,
name = name,
dscr = parts.description or name,
wordTrig = true,
}, body)

if ls_conf.autotrigger then
table.insert(auto_lang_snips, snip)
else
table.insert(lang_snips, snip)
end
end
end)
end
ls.snippets[lang] = lang_snips
ls.autosnippets[lang] = auto_lang_snips
end
end)
)
Expand Down

0 comments on commit 737a2e7

Please sign in to comment.