Skip to content

Commit

Permalink
slightly simplify snipmate-loader.
Browse files Browse the repository at this point in the history
Don't need RespectCollectionLaziness, was from earlier version.
Also don't have to load all extending filetypes in `add_file`, that
happens in `load_file`.
  • Loading branch information
L3MON4D3 committed Nov 19, 2023
1 parent afb6b1e commit 29bc71f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions lua/luasnip/loaders/from_snipmate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function Collection.new(root, lazy, include_ft, exclude_ft, add_opts, lazy_watch
o:register_file(path, file_ft)
if file_category == "load" then
-- actually load if allowed by in/exclude.
o:add_file(path, file_ft, "RespectCollectionLaziness")
o:add_file(path, file_ft)
end
end
end,
Expand Down Expand Up @@ -238,22 +238,17 @@ function Collection:register_file(path, ft)
self.collection_files_by_ft[ft][path] = true
end

--- @alias LuaSnip.Loaders.Snipmate.LazyMode
--- | '"Immediate"' Load file immediately, independent of collection.lazy.
--- | '"RespectCollectionLaziness"' Behave according to collection.lazy.

--- Register a file-filetype-association with the collection.
--- @param path string Path to a file that belongs to this collection.
--- @param add_ft string The original filetype this file should be added as.
--- Since we have to support filetype-extensions, this may
--- add the snippets of the file to several other
--- filetypes.
--- @param mode LuaSnip.Loaders.Snipmate.LazyMode
function Collection:add_file(path, add_ft, mode)
function Collection:add_file(path, add_ft)
-- register known file.
Data.snipmate_ft_paths[add_ft][path] = true

if mode == "RespectCollectionLaziness" and self.lazy then
if self.lazy then
if not session.loaded_fts[add_ft] then
log.info("Registering lazy-load-snippets for ft `%s` from file `%s`", add_ft, path)

Expand All @@ -268,10 +263,8 @@ function Collection:add_file(path, add_ft, mode)
end
end

-- load file for add_ft and all filetypes that inherit from it.
for _, ft in ipairs(self.ft_extensions:connected_component(add_ft, "Forward")) do
self:load_file(path, ft, "SkipIfLoaded")
end
-- extended filetypes will be loaded in load_file.
self:load_file(path, add_ft, "SkipIfLoaded")
end

--- @alias LuaSnip.Loaders.Snipmate.SkipLoad
Expand Down

0 comments on commit 29bc71f

Please sign in to comment.