diff options
| -rw-r--r-- | lua/clever_f/sequence_coordinator.lua | 34 | ||||
| -rw-r--r-- | tests/run.lua | 18 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lua/clever_f/sequence_coordinator.lua b/lua/clever_f/sequence_coordinator.lua index bcff504..d1316e6 100644 --- a/lua/clever_f/sequence_coordinator.lua +++ b/lua/clever_f/sequence_coordinator.lua @@ -90,10 +90,44 @@ function SequenceCoordinator:inspect_fold_open_policy(invocation) return fold_state end +local function fold_open_enabled(fold_state) + return fold_state:opens("horizontal") or fold_state:opens("all") +end + +function SequenceCoordinator:open_enclosing_folds(invocation, fold_state) + if type(invocation) ~= "table" or not domain.Position.is(invocation.position) then + fail("fold opening requires primary invocation state", 2) + end + if not domain.FoldState.is(fold_state) then + fail("fold opening requires FoldState", 2) + end + if not fold_open_enabled(fold_state) then + return 0 + end + + local host = coordinator_records[self].host + if type(host.open_fold) ~= "function" then + fail("SequenceCoordinator host must open folds", 2) + end + local opened = 0 + while fold_state.closed_levels > 0 do + if host:open_fold(invocation.position) ~= true then + break + end + opened = opened + 1 + fold_state = self:inspect_fold_open_policy(invocation) + end + return opened +end + function SequenceCoordinator:primary(value) local descriptor = self:validate_primary_descriptor(value) local invocation = self:read_primary_invocation() invocation.fold_state = self:inspect_fold_open_policy(invocation) + invocation.opened_folds = self:open_enclosing_folds( + invocation, + invocation.fold_state + ) return descriptor end diff --git a/tests/run.lua b/tests/run.lua index fe67fd3..345f146 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -7111,6 +7111,24 @@ test("Primary coordination inspects fold policy during preflight", function() truthy(host:read_fold_state():opens("horizontal")) end) +test("Primary preflight opens folds for horizontal and all policies", function() + for _, open_policy in ipairs({ "horizontal", "all" }) do + local host = MemoryHost.new({ + fold_open_policy = { open_policy }, + closed_fold_levels = 2, + }) + sequence_coordinator.new({ host = host }):primary("f") + same(0, host:read_fold_state().closed_levels, open_policy) + end + + local host = MemoryHost.new({ + fold_open_policy = { "jump" }, + closed_fold_levels = 2, + }) + sequence_coordinator.new({ host = host }):primary("f") + same(2, host:read_fold_state().closed_levels) +end) + for _, item in ipairs(tests) do local ok, failure = xpcall(item.body, debug.traceback) if not ok then |
