Skip to content

Commit 4e13374

Browse files
fiction example for invalidation function
1 parent 6112008 commit 4e13374

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

lua/luasnip/extras/expand_conditions.lua

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,42 @@ local memoization_mt = {
2424
-- low level factory
2525
-- invalidate(table) -> bool: decides if the memoization should be invalidated,
2626
-- can store state in table
27-
-- TODO provide invalidate defaults (buffer, cursor, changes, none)
2827
function M.memoization_factory(func, invalidate)
2928
-- always invalidare by default
3029
invalidate = invalidate or function() return true end
3130
return setmetatable({func=func, invalidate=invalidate}, memoization_mt)
3231
end
3332

34-
-------------
35-
-- PRESETS --
36-
-------------
33+
-------------------
34+
-- INVAL PRESETS --
35+
-------------------
36+
-- TODO provide invalidate defaults (buffer, cursor, changes, none)
37+
M.inval = {}
38+
-- just a small example to illustrate the usage (will most probably have to be
39+
-- changed)
40+
function M.inval.line(tab, _, _, _, line)
41+
return tab.line ~= line
42+
end
43+
44+
------------------
45+
-- COND PRESETS --
46+
------------------
3747
local function line_begin(line_to_cursor, matched_trigger)
3848
-- +1 because `string.sub("abcd", 1, -2)` -> abc
3949
return line_to_cursor:sub(1, -(#matched_trigger + 1)):match("^%s*$")
4050
end
41-
function M.line_begin() return M.memoization_factory(line_begin, nil) -- TODO invalidation function
51+
function M.line_begin()
52+
-- TODO invalidation function
53+
return M.memoization_factory(line_begin, nil)
4254
end
4355

4456
local function line_end(line_to_cursor)
4557
local line = vim.api.nvim_get_current_line()
4658
return #line_to_cursor == #line
4759
end
48-
function M.line_end() return M.memoization_factory(line_end, nil) -- TODO invalidation function
60+
function M.line_end()
61+
-- TODO invalidation function
62+
return M.memoization_factory(line_end, nil)
4963
end
5064

5165
return M

0 commit comments

Comments
 (0)