Skip to content

Commit

Permalink
Merge pull request #599 from atticus-sullivan/hotfix_nil_in_get_snippets
Browse files Browse the repository at this point in the history
Hotfix nil in get snippets + adds test for error
Closes #591
  • Loading branch information
L3MON4D3 authored Sep 15, 2022
2 parents 14b801f + 52220c5 commit 4dc7012
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/luasnip.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*luasnip.txt* For NVIM v0.5.0 Last change: 2022 September 14
*luasnip.txt* For NVIM v0.5.0 Last change: 2022 September 15

==============================================================================
Table of Contents *luasnip-table-of-contents*
Expand Down
1 change: 1 addition & 0 deletions lua/luasnip/session/snippet_collection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ function M.clean_invalidated(opts)

for type, type_snippets in pairs(by_ft) do
by_ft[type] = without_invalidated(type_snippets)
setmetatable(by_ft[type], by_ft_snippets_mt)

This comment has been minimized.

Copy link
@leiserfg

leiserfg Sep 15, 2022

Contributor

@L3MON4D3 should not this become a release?

This comment has been minimized.

Copy link
@L3MON4D3

L3MON4D3 Sep 15, 2022

Author Owner

That was my instinct as well xD
I went to create a release, only to notice that faulty commit isn't even released yet :D

I guess it makes sense to wait a few days after a higher-risk (big or touches integral part of luasnip) addition.

end

for key, key_snippets in pairs(by_key) do
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/snippet_collection_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,25 @@ describe("snippet_collection.add/get", function()
assert.is_true(foo())
end)
end)

describe("add_snippets invalidation", function()
-- apparently clear() needs to run before anything else...
helpers.clear()
helpers.exec("set rtp+=" .. os.getenv("LUASNIP_SOURCE"))

it("", function()
local function foo()
return helpers.exec_lua([[
local s,t = require("luasnip").snippet, require("luasnip").text_node
local collection = require("luasnip.session.snippet_collection")
collection.clear_snippets()
local s1,s2 = s("trig1", t("snippet1")), s("trig2", t("snippet2"))
local opts = {type="snippets", default_priority=1000, key="abc"}
collection.add_snippets({["txt"]={s1,s2}}, opts)
collection.clean_invalidated({ inv_limit = -1 })
local r = collection.get_snippets("nonExistantFT", "snippets")
]])
end
assert.has_no.errors(foo)
end)
end)

0 comments on commit 4dc7012

Please # to comment.