Skip to content

Commit 4dc7012

Browse files
authored
Merge pull request #599 from atticus-sullivan/hotfix_nil_in_get_snippets
Hotfix nil in get snippets + adds test for error Closes #591
2 parents 14b801f + 52220c5 commit 4dc7012

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

doc/luasnip.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*luasnip.txt* For NVIM v0.5.0 Last change: 2022 September 14
1+
*luasnip.txt* For NVIM v0.5.0 Last change: 2022 September 15
22

33
==============================================================================
44
Table of Contents *luasnip-table-of-contents*

lua/luasnip/session/snippet_collection.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ function M.clean_invalidated(opts)
217217

218218
for type, type_snippets in pairs(by_ft) do
219219
by_ft[type] = without_invalidated(type_snippets)
220+
setmetatable(by_ft[type], by_ft_snippets_mt)
220221
end
221222

222223
for key, key_snippets in pairs(by_key) do

tests/unit/snippet_collection_spec.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,25 @@ describe("snippet_collection.add/get", function()
4646
assert.is_true(foo())
4747
end)
4848
end)
49+
50+
describe("add_snippets invalidation", function()
51+
-- apparently clear() needs to run before anything else...
52+
helpers.clear()
53+
helpers.exec("set rtp+=" .. os.getenv("LUASNIP_SOURCE"))
54+
55+
it("", function()
56+
local function foo()
57+
return helpers.exec_lua([[
58+
local s,t = require("luasnip").snippet, require("luasnip").text_node
59+
local collection = require("luasnip.session.snippet_collection")
60+
collection.clear_snippets()
61+
local s1,s2 = s("trig1", t("snippet1")), s("trig2", t("snippet2"))
62+
local opts = {type="snippets", default_priority=1000, key="abc"}
63+
collection.add_snippets({["txt"]={s1,s2}}, opts)
64+
collection.clean_invalidated({ inv_limit = -1 })
65+
local r = collection.get_snippets("nonExistantFT", "snippets")
66+
]])
67+
end
68+
assert.has_no.errors(foo)
69+
end)
70+
end)

0 commit comments

Comments
 (0)