Previously, we could not
* add files that were not present when `load/lazy_load` was called to
the collection. This is pretty annoying if one wants to add
project-local snippets, or snippets for a new filetype (ofc).
* load collections whose directory/package.json(c) did not exist when
`load` was called.
This is also an annoyance when creating project-local snippets, since
a re-`load()` is required for the snippets to be picked up.
* pick up on changes to the snippet-files from another neovim-instance
(due to reloading on BufWritePost)
This patch fixes all of these by modularizing the loaders a bit more,
into one component ("Collection") which takes care of all the logic of
loading different files, and another ("fswatchers") which notify the
collections when a file-change is detected. This allows, first of all, a
better design where the first concern can be nullified, and secondly, us
to use libuvs api for file-watching, to implement the last two (if a
potentially non-existing collection should be loaded, we can use libuv
to wait for the collection-root/manifest-file, and create the collection
once that exists).
Another cool addition is the loader-snippet-cache, which makes it so
that the snippet files (for vscode and snipmate) are only loaded once
for all filetypes, and not once for each filetype. That's probably not
noticeable though, except if a collection with many extends/languages
for one json-file is loaded :D
Due to the neovim's issue (https://github.com/neovim/neovim/issues/16416),
using `vim.fn.expand` sometimes throws Keyboard interrupt error when
pressing Ctrl-C (a common alternative to Esc).
This works around the above issue by simply getting the buffer number
from event argument.
This can be used to load more than the buffers &filetype, for example,
if `ft_func` uses treesitter to correctly expand snippets in injected
regions, the buffers &filetype may not include all filetypes of these
regions.
So, via load_ft_func(bufnr) -> filetype[] (aka. list of strings), such
buffers can be detected and load snippets for all possible injected
regions.