From 726577ee00a6d96f6a0f5c1fa96b3a102dce175f Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Jan 2025 19:11:04 -0800 Subject: [PATCH] Cleanup --- lua/argonaut/param.lua | 36 ++++++++++++++++++++++-------------- lua/argonaut/range.lua | 9 +++++++-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lua/argonaut/param.lua b/lua/argonaut/param.lua index b1033b2..3522370 100644 --- a/lua/argonaut/param.lua +++ b/lua/argonaut/param.lua @@ -12,11 +12,17 @@ end function ParamCursorCell:hit_test(cursor) if self.cursor == cursor then - return {} + return {{ + type = 'cursor_cell', + value = self.cursor:get_value(), + }} end end -function ParamCursorCell:hit_search() +function ParamCursorCell:hit_search(trace, depth) + local frame = trace[depth] + assert(frame.type == 'cursor_cell') + return self.cursor end @@ -32,10 +38,6 @@ function ParamCursorCell:is_empty() return not self.cursor:get_value():match('%S') end -function ParamCursorCell:get_type() - return 'cursor' -end - local ParamRangeCell = {} ParamRangeCell.__index = ParamRangeCell @@ -49,11 +51,18 @@ function ParamRangeCell:write(builder, wrapped) end function ParamRangeCell:hit_test(cursor) - return self.range:hit_test(cursor) + local trace = self.range:hit_test(cursor) + if trace then + table.insert(trace, 1, {type = 'range_cell'}) + return trace + end end function ParamRangeCell:hit_search(trace, depth) - return self.range:hit_search(trace, depth) + local frame = trace[depth] + assert(frame.type == 'range_cell') + + return self.range:hit_search(trace, depth + 1) end function ParamRangeCell:get_start_row() @@ -68,10 +77,6 @@ function ParamRangeCell:is_empty() return false end -function ParamRangeCell:get_type() - return 'range' -end - local Param = {} Param.__index = Param @@ -108,8 +113,7 @@ function Param:hit_test(cursor) table.insert(trace, 1, { index = i, length = #self.cells, - subtype = cell:get_type(), - type='param_cell', + type = 'param_cell', }) return trace @@ -119,6 +123,10 @@ end function Param:hit_search(trace, depth) local frame = trace[depth] + assert(frame.index <= #self.cells) + assert(frame.length == #self.cells) + assert(frame.type == 'param_cell') + return self.cells[frame.index]:hit_search(trace, depth + 1) end diff --git a/lua/argonaut/range.lua b/lua/argonaut/range.lua index e2a8e67..19fa87e 100644 --- a/lua/argonaut/range.lua +++ b/lua/argonaut/range.lua @@ -111,8 +111,8 @@ function Range:hit_test(cursor) table.insert(trace, 1, { index = i, length = #self.params, - subtype = self.pairing.open, type = 'range_param', + value = self.pairing.open, }) return trace @@ -122,14 +122,19 @@ function Range:hit_test(cursor) return { index = 0, length = #self.params, - subtype = self.pairing.open, type = 'range_padding', + value = self.pairing.open, } end end function Range:hit_search(trace, depth) local frame = trace[depth] + assert(frame.index <= #self.params) + assert(frame.length == #self.params) + assert(frame.type == 'range_param') + assert(frame.value == self.pairing.open) + if frame.index == 0 then return self.start_cursor else