Skip to content

Commit 3e65920

Browse files
chore(refactor): move debug_marks module out of core into debug folder
1 parent 6f87257 commit 3e65920

File tree

7 files changed

+59
-80
lines changed

7 files changed

+59
-80
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### Features
66

77
- logging improvements [2b86631](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/2b86631c153e24682a1a2d05e37a0f4f94e9b827)
8+
- table min width [f84eeae](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/f84eeaebac278e26bd2906fd47747631716a5edb)
9+
- new debug API for development [6f87257](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/6f8725746ecadae0ae5ab3e7a1a445dad6b2e231)
810

911
### Bug Fixes
1012

lua/render-markdown/api.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ end
3535
function M.debug()
3636
local buf = vim.api.nvim_get_current_buf()
3737
local row, marks = require('render-markdown.core.ui').get_row_marks(buf)
38-
require('render-markdown.core.debug_marks').debug(row, marks)
38+
require('render-markdown.debug.marks').debug(row, marks)
3939
end
4040

4141
return M

lua/render-markdown/core/node_info.lua

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@ function NodeInfo.new(buf, node)
2727
return self
2828
end
2929

30-
---@param infos render.md.NodeInfo[]
31-
---@return render.md.NodeInfo[]
32-
function NodeInfo.sort_inplace(infos)
33-
table.sort(infos, function(a, b)
34-
if a.start_row ~= b.start_row then
35-
return a.start_row < b.start_row
36-
else
37-
return a.start_col < b.start_col
38-
end
39-
end)
40-
return infos
30+
---@param a render.md.NodeInfo
31+
---@param b render.md.NodeInfo
32+
---@return boolean
33+
function NodeInfo.__lt(a, b)
34+
if a.start_row ~= b.start_row then
35+
return a.start_row < b.start_row
36+
else
37+
return a.start_col < b.start_col
38+
end
4139
end
4240

4341
---@return boolean

lua/render-markdown/core/debug_marks.lua renamed to lua/render-markdown/debug/marks.lua

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
---@class render.md.DebugMark
1+
---@class render.md.debug.Mark
22
---@field conceal boolean
33
---@field opts vim.api.keyset.set_extmark
44
---@field row { [1]: integer, [2]: integer }
55
---@field col { [1]: integer, [2]: integer }
6-
local DebugMark = {}
7-
DebugMark.__index = DebugMark
6+
local Mark = {}
7+
Mark.__index = Mark
88

99
---@param mark render.md.Mark
10-
---@return render.md.DebugMark
11-
function DebugMark.new(mark)
12-
local self = setmetatable({}, DebugMark)
10+
---@return render.md.debug.Mark
11+
function Mark.new(mark)
12+
local self = setmetatable({}, Mark)
1313
self.conceal, self.opts = mark.conceal, mark.opts
1414
self.row = { mark.start_row, mark.opts.end_row or mark.start_row }
1515
self.col = { mark.start_col, mark.opts.end_col or mark.start_col }
1616
return self
1717
end
1818

1919
---@return integer[]
20-
function DebugMark:priorities()
20+
function Mark:priorities()
2121
local row_offset = 0
2222
if self.opts.virt_lines ~= nil then
2323
row_offset = self.opts.virt_lines_above and -0.5 or 0.5
@@ -28,7 +28,7 @@ function DebugMark:priorities()
2828
end
2929

3030
---@return string
31-
function DebugMark:__tostring()
31+
function Mark:__tostring()
3232
---@param text string
3333
---@return string
3434
local function serialize_text(text)
@@ -119,10 +119,10 @@ function DebugMark:__tostring()
119119
return table.concat(lines, '\n')
120120
end
121121

122-
---@param a render.md.DebugMark
123-
---@param b render.md.DebugMark
122+
---@param a render.md.debug.Mark
123+
---@param b render.md.debug.Mark
124124
---@return boolean
125-
function DebugMark.__lt(a, b)
125+
function Mark.__lt(a, b)
126126
local as, bs = a:priorities(), b:priorities()
127127
for i = 1, math.max(#as, #bs) do
128128
if as[i] ~= bs[i] then
@@ -132,17 +132,17 @@ function DebugMark.__lt(a, b)
132132
return false
133133
end
134134

135-
---@class render.md.DebugMarks
135+
---@class render.md.debug.Marks
136136
local M = {}
137137

138138
---@param row integer
139139
---@param marks render.md.Mark[]
140140
function M.debug(row, marks)
141-
print('Decorations on row: ' .. row)
141+
print(string.format('Decorations on row: %d', row))
142142
if #marks == 0 then
143143
print('No decorations found')
144144
end
145-
local debug_marks = vim.tbl_map(DebugMark.new, marks)
145+
local debug_marks = vim.tbl_map(Mark.new, marks)
146146
table.sort(debug_marks)
147147
for _, mark in ipairs(debug_marks) do
148148
print(mark)

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.0.4'
7+
M.version = '7.0.5'
88

99
function M.check()
1010
M.start('version')

lua/render-markdown/render/table.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ function Render:setup()
7070
end
7171

7272
local rows = {}
73-
for _, table_row in ipairs(NodeInfo.sort_inplace(table_rows)) do
73+
table.sort(table_rows)
74+
for _, table_row in ipairs(table_rows) do
7475
local row = self:parse_row(table_row, #delim.columns)
7576
if row ~= nil then
7677
table.insert(rows, row)
@@ -169,7 +170,9 @@ function Render.parse_row_data(row, cell_type)
169170
if #pipes == 0 or #cells == 0 or #pipes ~= #cells + 1 then
170171
return nil, nil
171172
end
172-
return NodeInfo.sort_inplace(pipes), NodeInfo.sort_inplace(cells)
173+
table.sort(pipes)
174+
table.sort(cells)
175+
return pipes, cells
173176
end
174177

175178
function Render:render()

tests/util.lua

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ function Row:increment(n)
2828
end
2929

3030
---@class render.md.MarkInfo
31-
---@field row integer[]
32-
---@field col integer[]
31+
---@field row { [1]: integer, [2]?: integer }
32+
---@field col { [1]: integer, [2]?: integer }
3333
---@field hl_eol? boolean
3434
---@field hl_group? string
3535
---@field conceal? string
@@ -65,61 +65,37 @@ function MarkInfo.new(row, col, details)
6565
return self
6666
end
6767

68-
---@param a render.md.MarkInfo
69-
---@param b render.md.MarkInfo
70-
---@return boolean
71-
function MarkInfo.__lt(a, b)
72-
---@param getter fun(mark: render.md.MarkInfo): number[]
73-
---@return boolean?
74-
local function compare_ints(getter)
75-
local as, bs = getter(a), getter(b)
76-
for i = 1, math.max(#as, #bs) do
77-
local av, bv = as[math.min(i, #as)], bs[math.min(i, #bs)]
78-
if av ~= bv then
79-
return av < bv
80-
end
81-
end
82-
return nil
83-
end
68+
---@return integer[]
69+
function MarkInfo:priorities()
70+
local result = {}
8471

85-
local row_comp = compare_ints(function(mark)
86-
if mark.virt_lines == nil then
87-
return mark.row
88-
end
89-
local offset = mark.virt_lines_above and -0.5 or 0.5
90-
return vim.iter(mark.row)
91-
:map(function(row)
92-
return row + offset
93-
end)
94-
:totable()
95-
end)
96-
if row_comp ~= nil then
97-
return row_comp
72+
local row_offset = 0
73+
if self.virt_lines ~= nil then
74+
row_offset = self.virt_lines_above and -0.5 or 0.5
9875
end
76+
vim.list_extend(result, { self.row[1] + row_offset, (self.row[2] or self.row[1]) + row_offset })
9977

100-
local col_comp = compare_ints(function(mark)
101-
if mark.virt_text_win_col == nil then
102-
return mark.col
103-
else
104-
return { mark.virt_text_win_col }
105-
end
106-
end)
107-
if col_comp ~= nil then
108-
return col_comp
109-
end
78+
local col = self.virt_text_win_col or 0
79+
vim.list_extend(result, { math.max(self.col[1], col), math.max((self.col[2] or self.col[1]), col) })
11080

111-
-- Higher priority for inline text
112-
local a_inline, b_inline = a.virt_text_pos == 'inline', b.virt_text_pos == 'inline'
113-
if a_inline ~= b_inline then
114-
return a_inline
115-
end
81+
vim.list_extend(result, {
82+
self.virt_text_pos == 'inline' and 0 or 1, -- Inline text comes first
83+
self.sign_text == nil and 0 or 1, -- Signs come later
84+
})
11685

117-
-- Lower priority for signs
118-
local a_sign, b_sign = a.sign_text ~= nil, b.sign_text ~= nil
119-
if a_sign ~= b_sign then
120-
return not a_sign
121-
end
86+
return result
87+
end
12288

89+
---@param a render.md.MarkInfo
90+
---@param b render.md.MarkInfo
91+
---@return boolean
92+
function MarkInfo.__lt(a, b)
93+
local as, bs = a:priorities(), b:priorities()
94+
for i = 1, math.max(#as, #bs) do
95+
if as[i] ~= bs[i] then
96+
return as[i] < bs[i]
97+
end
98+
end
12399
return false
124100
end
125101

0 commit comments

Comments
 (0)