From 711e80022653240e8ad2db4c4a6d900e026394a4 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Jan 2025 18:24:01 -0800 Subject: [PATCH] Add debug info --- lua/argonaut/init.lua | 14 ++++++++++++++ lua/argonaut/param.lua | 22 ++++++++++++++++++---- lua/argonaut/range.lua | 35 +++++++++++++++++++---------------- plugin/argonaut.lua | 7 +++++++ 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/lua/argonaut/init.lua b/lua/argonaut/init.lua index b15aa18..f5a1f5a 100644 --- a/lua/argonaut/init.lua +++ b/lua/argonaut/init.lua @@ -38,7 +38,21 @@ local function reflow() return true 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 { + inspect = inspect, reflow = reflow, setup = Options.setup, } diff --git a/lua/argonaut/param.lua b/lua/argonaut/param.lua index 0140116..b1033b2 100644 --- a/lua/argonaut/param.lua +++ b/lua/argonaut/param.lua @@ -32,6 +32,10 @@ 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,7 +53,7 @@ function ParamRangeCell:hit_test(cursor) end function ParamRangeCell:hit_search(trace, depth) - return self.range:hit_search(trace, depth + 1) + return self.range:hit_search(trace, depth) end function ParamRangeCell:get_start_row() @@ -64,6 +68,10 @@ function ParamRangeCell:is_empty() return false end +function ParamRangeCell:get_type() + return 'range' +end + local Param = {} Param.__index = Param @@ -97,15 +105,21 @@ function Param:hit_test(cursor) for i, cell in ipairs(self.cells) do local trace = cell:hit_test(cursor) 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 end end end function Param:hit_search(trace, depth) - local index = trace[depth] - return self.cells[index]:hit_search(trace, depth) + local frame = trace[depth] + return self.cells[frame.index]:hit_search(trace, depth + 1) end function Param:write(builder, wrapped) diff --git a/lua/argonaut/range.lua b/lua/argonaut/range.lua index 2e6924b..e2a8e67 100644 --- a/lua/argonaut/range.lua +++ b/lua/argonaut/range.lua @@ -105,32 +105,35 @@ end function Range:hit_test(cursor) if self:contains(cursor) then - local trace = nil for i, param in pairs(self.params) do - local trace_param = param:hit_test(cursor) - if trace_param then - trace = {i} - for _, trace_param_frame in ipairs(trace_param) do - table.insert(trace, trace_param_frame) - end - break + local trace = param:hit_test(cursor) + if trace then + table.insert(trace, 1, { + index = i, + length = #self.params, + subtype = self.pairing.open, + type = 'range_param', + }) + + return trace end end - if not trace then - trace = {0} - end - - return trace + return { + index = 0, + length = #self.params, + subtype = self.pairing.open, + type = 'range_padding', + } end end function Range:hit_search(trace, depth) - local index = trace[depth] - if index == 0 then + local frame = trace[depth] + if frame.index == 0 then return self.start_cursor else - return self.params[index]:hit_search(trace, depth + 1) + return self.params[frame.index]:hit_search(trace, depth + 1) end end diff --git a/plugin/argonaut.lua b/plugin/argonaut.lua index 43520d0..9b173bf 100644 --- a/plugin/argonaut.lua +++ b/plugin/argonaut.lua @@ -8,11 +8,18 @@ if not vim.g.argonaut_loaded then end local function argonaut_reflow() + argonaut_reload() require('argonaut').reflow() 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('ArgonautReflow', argonaut_reflow, {}) + vim.api.nvim_create_user_command('ArgonautInspect', argonaut_inspect, {}) vim.g.argonaut_loaded = true end