diff options
| -rw-r--r-- | lua/clever_f/motion_executor.lua | 23 | ||||
| -rw-r--r-- | tests/run.lua | 29 |
2 files changed, 51 insertions, 1 deletions
diff --git a/lua/clever_f/motion_executor.lua b/lua/clever_f/motion_executor.lua index cc3cc56..72a66bd 100644 --- a/lua/clever_f/motion_executor.lua +++ b/lua/clever_f/motion_executor.lua @@ -1,6 +1,7 @@ local destination_engine = require("clever_f.destination_engine") local domain = require("clever_f.domain") local sequence_state = require("clever_f.sequence_state") +local state_transitions = require("clever_f.state_transitions") local text_topology = require("clever_f.text_topology") local M = {} @@ -105,6 +106,16 @@ local function require_state(state) return state end +local function require_transitions(transitions, state) + transitions = transitions or state_transitions.new(state) + if type(transitions) ~= "table" + or type(transitions.CommitCommandSuccess) ~= "function" + then + fail("MotionExecutor transitions must commit command success", 3) + end + return transitions +end + local executor_metatable = { __index = MotionExecutor, __newindex = function() @@ -123,6 +134,7 @@ function MotionExecutor.new(options, dependencies) end local executor = setmetatable({}, executor_metatable) + local state = require_state(options.state) executor_records[executor] = { host = require_host(options.host), destination_engine = require_destination_engine( @@ -131,7 +143,11 @@ function MotionExecutor.new(options, dependencies) feedback_service = require_feedback_service( options.feedback_service or options.feedback ), - state = require_state(options.state), + state = state, + transitions = require_transitions( + options.transitions or options.state_transitions, + state + ), } return executor end @@ -208,6 +224,11 @@ function MotionExecutor:_execute_command(request) outcome.endpoint ) migrate_command_feedback(self, request, origin, outcome) + executor_records[self].transitions:CommitCommandSuccess( + request.context, + outcome.endpoint, + request.moved_forward + ) return domain.ActionOutcome.from_search(outcome, request.plan.descriptor) end diff --git a/tests/run.lua b/tests/run.lua index 09a0375..97fbacb 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -3311,6 +3311,35 @@ test("Command success requests feedback migration before state commit", function falsy(observed.moved_forward) end) +test("Complete command execution commits direction and landing", function() + local state, transitions = fresh_sequence_state() + local target_value = target("a") + transitions:BeginAcquisition("n", "f") + transitions:CommitAcquiredTarget("n", target_value) + + local host = MemoryHost.new({ + buffer_lines = { "aba" }, + cursor = { line = 1, byte_column = 1 }, + }) + local plan = motion_plan.build( + target_plan.build(target_value, matching_policy()), + "f" + ) + local outcome = motion_executor.new(host):execute( + text_topology.from_host(host), + "n", + plan, + 1, + true + ) + + same(domain.ActionKind.MOVEMENT, outcome.kind) + same(domain.Position.new(1, 3), state:get_previous_landing("n")) + falsy(state:get_first_move("n")) + truthy(state.moved_forward) + truthy(state.moved_forward_initialized) +end) + for _, item in ipairs(tests) do local ok, failure = xpcall(item.body, debug.traceback) if not ok then |
