1

Add debug info

This commit is contained in:
Alex Yatskov 2025-01-18 18:24:01 -08:00
parent 6ebe65a9e4
commit 711e800226
4 changed files with 58 additions and 20 deletions

View File

@ -38,7 +38,21 @@ local function reflow()
return true return true
end end
local function inspect()
local range = Range.find_closest()
if range then
local trace = range:hit_test(Cursor.get_current())
assert(trace)
print('--- range start ---')
dump(trace)
print('--- range stop ---')
else
print('no range found!')
end
end
return { return {
inspect = inspect,
reflow = reflow, reflow = reflow,
setup = Options.setup, setup = Options.setup,
} }

View File

@ -32,6 +32,10 @@ function ParamCursorCell:is_empty()
return not self.cursor:get_value():match('%S') return not self.cursor:get_value():match('%S')
end end
function ParamCursorCell:get_type()
return 'cursor'
end
local ParamRangeCell = {} local ParamRangeCell = {}
ParamRangeCell.__index = ParamRangeCell ParamRangeCell.__index = ParamRangeCell
@ -49,7 +53,7 @@ function ParamRangeCell:hit_test(cursor)
end end
function ParamRangeCell:hit_search(trace, depth) function ParamRangeCell:hit_search(trace, depth)
return self.range:hit_search(trace, depth + 1) return self.range:hit_search(trace, depth)
end end
function ParamRangeCell:get_start_row() function ParamRangeCell:get_start_row()
@ -64,6 +68,10 @@ function ParamRangeCell:is_empty()
return false return false
end end
function ParamRangeCell:get_type()
return 'range'
end
local Param = {} local Param = {}
Param.__index = Param Param.__index = Param
@ -97,15 +105,21 @@ function Param:hit_test(cursor)
for i, cell in ipairs(self.cells) do for i, cell in ipairs(self.cells) do
local trace = cell:hit_test(cursor) local trace = cell:hit_test(cursor)
if trace then if trace then
table.insert(trace, 1, i) table.insert(trace, 1, {
index = i,
length = #self.cells,
subtype = cell:get_type(),
type='param_cell',
})
return trace return trace
end end
end end
end end
function Param:hit_search(trace, depth) function Param:hit_search(trace, depth)
local index = trace[depth] local frame = trace[depth]
return self.cells[index]:hit_search(trace, depth) return self.cells[frame.index]:hit_search(trace, depth + 1)
end end
function Param:write(builder, wrapped) function Param:write(builder, wrapped)

View File

@ -105,32 +105,35 @@ end
function Range:hit_test(cursor) function Range:hit_test(cursor)
if self:contains(cursor) then if self:contains(cursor) then
local trace = nil
for i, param in pairs(self.params) do for i, param in pairs(self.params) do
local trace_param = param:hit_test(cursor) local trace = param:hit_test(cursor)
if trace_param then if trace then
trace = {i} table.insert(trace, 1, {
for _, trace_param_frame in ipairs(trace_param) do index = i,
table.insert(trace, trace_param_frame) length = #self.params,
end subtype = self.pairing.open,
break type = 'range_param',
end })
end
if not trace then
trace = {0}
end
return trace return trace
end end
end
return {
index = 0,
length = #self.params,
subtype = self.pairing.open,
type = 'range_padding',
}
end
end end
function Range:hit_search(trace, depth) function Range:hit_search(trace, depth)
local index = trace[depth] local frame = trace[depth]
if index == 0 then if frame.index == 0 then
return self.start_cursor return self.start_cursor
else else
return self.params[index]:hit_search(trace, depth + 1) return self.params[frame.index]:hit_search(trace, depth + 1)
end end
end end

View File

@ -8,11 +8,18 @@ if not vim.g.argonaut_loaded then
end end
local function argonaut_reflow() local function argonaut_reflow()
argonaut_reload()
require('argonaut').reflow() require('argonaut').reflow()
end end
local function argonaut_inspect()
argonaut_reload()
require('argonaut').inspect()
end
vim.api.nvim_create_user_command('ArgonautReload', argonaut_reload, {}) vim.api.nvim_create_user_command('ArgonautReload', argonaut_reload, {})
vim.api.nvim_create_user_command('ArgonautReflow', argonaut_reflow, {}) vim.api.nvim_create_user_command('ArgonautReflow', argonaut_reflow, {})
vim.api.nvim_create_user_command('ArgonautInspect', argonaut_inspect, {})
vim.g.argonaut_loaded = true vim.g.argonaut_loaded = true
end end