Skip to content

Commit

Permalink
vscode-loader: don't error on cleanup (close #1163).
Browse files Browse the repository at this point in the history
  • Loading branch information
L3MON4D3 committed Apr 21, 2024
1 parent 03c8e67 commit f8eb1e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lua/luasnip/loaders/from_vscode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,16 @@ function Collection.new(
end
end

local watcher_ok, err = pcall(path_watcher, manifest_path, {
local ok, watcher_or_err = pcall(path_watcher, manifest_path, {
-- don't handle removals for now.
add = update_manifest,
change = update_manifest,
}, { lazy = lazy_watcher, fs_event_providers = fs_event_providers })

if not watcher_ok then
error(("Could not create watcher: %s"):format(err))
if not ok then
error(("Could not create watcher: %s"):format(watcher_or_err))
end
o.manifest_watcher = watcher_ok
o.manifest_watcher = watcher_or_err

log.info("Initialized snippet-collection with manifest %s", manifest_path)

Expand Down
22 changes: 22 additions & 0 deletions tests/integration/loaders_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ describe("loaders:", function()
)
end)

for_all_loaders("removes all snippets when cleanup is called.", function()
-- make sure the loader worked.
feed("iall1")
exec_lua("ls.expand()")
screen:expect({
grid = [[
expands? jumps? ^ ! |
{0:~ }|
{0:~ }|
{0:~ }|
{2:-- INSERT --} |]],
})

exec_lua("ls.cleanup()")
feed("<Esc>ccall1")
exec_lua("ls.expand()")
screen:expect({grid = [[
all1^ |
{0:~ }|*3
{2:-- INSERT --} |]]})
end)

it("Can lazy-load from multiple sources", function()
ls_helpers.loaders["snipmate(lazy)"]("snippets")
ls_helpers.loaders["vscode(lazy)"]()
Expand Down

0 comments on commit f8eb1e7

Please sign in to comment.