1

More debug stuff

This commit is contained in:
Alex Yatskov 2025-01-18 19:25:38 -08:00
parent 726577ee00
commit fb58f7ad42
2 changed files with 24 additions and 27 deletions

View File

@ -14,7 +14,7 @@ function ParamCursorCell:hit_test(cursor)
if self.cursor == cursor then
return {{
type = 'cursor_cell',
value = self.cursor:get_value(),
char = self.cursor:get_value(),
}}
end
end
@ -111,9 +111,9 @@ function Param:hit_test(cursor)
local trace = cell:hit_test(cursor)
if trace then
table.insert(trace, 1, {
index = i,
length = #self.cells,
type = 'param_cell',
type = 'param',
cell_count = #self.cells,
cell_index = i,
})
return trace
@ -123,11 +123,11 @@ 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')
assert(frame.type == 'param')
assert(frame.cell_count == #self.cells)
assert(frame.cell_index <= #self.cells)
return self.cells[frame.index]:hit_search(trace, depth + 1)
return self.cells[frame.cell_index]:hit_search(trace, depth + 1)
end
function Param:write(builder, wrapped)

View File

@ -105,40 +105,37 @@ end
function Range:hit_test(cursor)
if self:contains(cursor) then
local frame = {
type = 'range',
pairing = self.pairing.open .. self.pairing.close,
param_count = #self.params,
param_index = 0,
}
for i, param in pairs(self.params) do
local trace = param:hit_test(cursor)
if trace then
table.insert(trace, 1, {
index = i,
length = #self.params,
type = 'range_param',
value = self.pairing.open,
})
frame.param_index = i
table.insert(trace, 1, frame)
return trace
end
end
return {
index = 0,
length = #self.params,
type = 'range_padding',
value = self.pairing.open,
}
return {frame}
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)
assert(frame.type == 'range')
assert(frame.pairing == self.pairing.open .. self.pairing.close)
assert(frame.param_count == #self.params)
assert(frame.param_index <= #self.params)
if frame.index == 0 then
if frame.param_index == 0 then
return self.start_cursor
else
return self.params[frame.index]:hit_search(trace, depth + 1)
return self.params[frame.param_index]:hit_search(trace, depth + 1)
end
end