Skip to content

Commit 6531aa7

Browse files
feat: include removed values in config diff
## Details The diff logic currently provides the user value if some part of the configuration is modified. What this means is if a user provides fewer values (by setting a list to the empty list for example) then no difference is shown. To fix this if the user value for some key is `nil` we set the value to `vim.NIL`. That way we can identify values as having been removed compared to the default in a unique way. Minor other change: - update ad-hoc unit tests to remove bullet point and add more link tests - move setup of debug row logic out of api and into the module
1 parent e78a276 commit 6531aa7

File tree

8 files changed

+87
-86
lines changed

8 files changed

+87
-86
lines changed

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.11.0 Last change: 2025 April 23
1+
*render-markdown.txt* For 0.11.0 Last change: 2025 April 24
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/api.lua

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local Env = require('render-markdown.lib.env')
21
local manager = require('render-markdown.manager')
32
local state = require('render-markdown.state')
43

@@ -30,8 +29,7 @@ function M.buf_toggle()
3029
end
3130

3231
function M.log()
33-
local log = require('render-markdown.core.log')
34-
log.open()
32+
require('render-markdown.core.log').open()
3533
end
3634

3735
function M.expand()
@@ -45,18 +43,13 @@ function M.contract()
4543
end
4644

4745
function M.debug()
48-
local ui = require('render-markdown.core.ui')
49-
local disply = require('render-markdown.debug.marks')
50-
local buf = Env.buf.current()
51-
local win = Env.win.current()
52-
local row, marks = ui.get_row_marks(buf, win)
53-
disply.show(row, marks)
46+
require('render-markdown.debug.marks').show()
5447
end
5548

5649
function M.config()
5750
local difference = state.difference()
58-
if vim.tbl_count(difference) == 0 then
59-
vim.print('Default Configuration')
51+
if difference == nil then
52+
vim.print('default configuration')
6053
else
6154
vim.print(difference)
6255
end

lua/render-markdown/core/ui.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,21 @@ function M.invalidate_cache()
5353
end
5454

5555
---@param buf integer
56-
---@param win integer
57-
---@return integer, render.md.Mark[]
58-
function M.get_row_marks(buf, win)
56+
---@param row integer
57+
---@return render.md.Mark[]
58+
function M.row_marks(buf, row)
5959
local config = state.get(buf)
6060
local buffer = Cache.get(buf)
6161
local mode = Env.mode.get()
62-
local row = assert(Env.row.get(buf, win), 'Row must be known')
63-
local hidden = assert(config:hidden(mode, row), 'Range must be known')
62+
local hidden = assert(config:hidden(mode, row), 'range must be known')
6463

6564
local marks = {}
6665
for _, extmark in ipairs(buffer:get_marks()) do
6766
if extmark:overlaps(hidden) then
6867
marks[#marks + 1] = extmark:get()
6968
end
7069
end
71-
return row, marks
70+
return marks
7271
end
7372

7473
---@private

lua/render-markdown/debug/diff.lua

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,28 @@ local M = {}
55

66
---@param t1 table<render.md.debug.Key, any>
77
---@param t2 table<render.md.debug.Key, any>
8-
---@return table<render.md.debug.Key, any>
8+
---@return table<render.md.debug.Key, any>?
99
function M.get(t1, t2)
10-
local result, keys = {}, {}
11-
M.append_keys(keys, t1)
12-
M.append_keys(keys, t2)
10+
local keys = vim.tbl_keys(t1)
11+
for key in pairs(t2) do
12+
if not vim.tbl_contains(keys, key) then
13+
keys[#keys + 1] = key
14+
end
15+
end
16+
local result = {}
1317
for _, key in ipairs(keys) do
18+
local difference = nil
1419
local v1, v2 = t1[key], t2[key]
1520
if type(v1) == 'table' and type(v2) == 'table' then
16-
local nested = M.get(v1, v2)
17-
if vim.tbl_count(nested) > 0 then
18-
result[key] = nested
19-
end
21+
difference = M.get(v1, v2)
22+
elseif v2 == nil then
23+
difference = vim.NIL
2024
elseif v1 ~= v2 then
21-
result[key] = v2
22-
end
23-
end
24-
return result
25-
end
26-
27-
---@private
28-
---@param keys render.md.debug.Key[]
29-
---@param t table<render.md.debug.Key, any>
30-
function M.append_keys(keys, t)
31-
for key in pairs(t) do
32-
if not vim.tbl_contains(keys, key) then
33-
keys[#keys + 1] = key
25+
difference = v2
3426
end
27+
result[key] = difference
3528
end
29+
return vim.tbl_count(result) > 0 and result or nil
3630
end
3731

3832
return M

lua/render-markdown/debug/marks.lua

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local Iter = require('render-markdown.lib.iter')
2-
31
---@class render.md.debug.Range
42
---@field [1] integer
53
---@field [2]? integer
@@ -148,12 +146,19 @@ end
148146
---@class render.md.debug.Marks
149147
local M = {}
150148

151-
---@param row integer
152-
---@param marks render.md.Mark[]
153-
function M.show(row, marks)
154-
vim.print(string.format('Row: %d', row))
149+
function M.show()
150+
local Env = require('render-markdown.lib.env')
151+
local Iter = require('render-markdown.lib.iter')
152+
local ui = require('render-markdown.core.ui')
153+
154+
local buf = Env.buf.current()
155+
local win = Env.win.current()
156+
local row = assert(Env.row.get(buf, win), 'row must be known')
157+
local marks = ui.row_marks(buf, row)
158+
159+
vim.print(string.format('row: %d', row))
155160
if #marks == 0 then
156-
vim.print('No decorations found')
161+
vim.print('no decorations found')
157162
else
158163
local debug_marks = Iter.list.map(marks, Mark.new)
159164
table.sort(debug_marks)

lua/render-markdown/health.lua

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

77
---@private
8-
M.version = '8.3.9'
8+
M.version = '8.3.10'
99

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

lua/render-markdown/state.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function M.invalidate_cache()
4343
Cache = {}
4444
end
4545

46-
---@return table
46+
---@return table?
4747
function M.difference()
4848
local default = require('render-markdown').default
4949
return require('render-markdown.debug.diff').get(default, M.config)

tests/ad_hoc_spec.lua

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,73 +35,83 @@ describe('ad hoc', function()
3535
end)
3636

3737
it('shortcut', function()
38-
util.setup.text({ '- [Normal Shortcut]' })
38+
util.setup.text({ '[Normal Shortcut]' })
3939
local marks = util.marks()
40-
marks:add(0, 0, 0, 2, util.bullet(1))
41-
util.assert_view(marks, { '● Normal Shortcut' })
40+
util.assert_view(marks, { 'Normal Shortcut' })
41+
end)
42+
43+
it('image', function()
44+
util.setup.text({ '![test](test.png)' })
45+
local marks = util.marks()
46+
marks:add(0, nil, 0, nil, util.link('image'))
47+
util.assert_view(marks, { '󰥶 test' })
4248
end)
4349

4450
it('wikilink', function()
45-
util.setup.text({ '- [[Basic One]] Then normal text' })
51+
util.setup.text({ '[[Basic One]] Then normal text' })
4652
local marks = util.marks()
47-
marks:add(0, 0, 0, 2, util.bullet(1))
48-
marks:add(0, 0, 2, 3, util.conceal())
49-
marks:add(0, nil, 3, nil, util.link('wiki'))
50-
marks:add(0, 0, 14, 15, util.conceal())
51-
util.assert_view(marks, { '● 󱗖 Basic One Then normal text' })
53+
marks:add(0, 0, 0, 1, util.conceal())
54+
marks:add(0, nil, 1, nil, util.link('wiki'))
55+
marks:add(0, 0, 12, 13, util.conceal())
56+
util.assert_view(marks, { '󱗖 Basic One Then normal text' })
5257
end)
5358

5459
it('wikilink with alias', function()
55-
util.setup.text({ '- [[Nickname|With Alias]] Something important' })
60+
util.setup.text({ '[[Nickname|With Alias]] Something important' })
61+
local marks = util.marks()
62+
marks:add(0, 0, 0, 1, util.conceal())
63+
marks:add(0, nil, 1, nil, util.link('wiki'))
64+
marks:add(0, 0, 2, 11, util.conceal())
65+
marks:add(0, 0, 22, 23, util.conceal())
66+
util.assert_view(marks, { '󱗖 With Alias Something important' })
67+
end)
68+
69+
it('wikilink media', function()
70+
util.setup.text({ '![[test.png]]' })
5671
local marks = util.marks()
57-
marks:add(0, 0, 0, 2, util.bullet(1))
58-
marks:add(0, 0, 2, 3, util.conceal())
59-
marks:add(0, nil, 3, nil, util.link('wiki'))
60-
marks:add(0, 0, 4, 13, util.conceal())
61-
marks:add(0, 0, 24, 25, util.conceal())
62-
util.assert_view(marks, { '● 󱗖 With Alias Something important' })
72+
marks:add(0, nil, 0, nil, util.link('image'))
73+
marks:add(0, 0, 1, 2, util.conceal())
74+
marks:add(0, nil, 2, nil, util.link('wiki'))
75+
marks:add(0, 0, 12, 13, util.conceal())
76+
util.assert_view(marks, { '󰥶 󱗖 test.png' })
6377
end)
6478

6579
it('email', function()
66-
util.setup.text({ '- <[email protected]> Email' })
80+
util.setup.text({ '<[email protected]> Email' })
6781
local marks = util.marks()
68-
marks:add(0, 0, 0, 2, util.bullet(1))
69-
marks:add(0, nil, 2, nil, util.link('email'))
70-
marks:add(0, 0, 2, 3, util.conceal())
71-
marks:add(0, 0, 2, 20, util.highlight('link'))
72-
marks:add(0, 0, 19, 20, util.conceal())
73-
util.assert_view(marks, { '● 󰀓 [email protected] Email' })
82+
marks:add(0, nil, 0, nil, util.link('email'))
83+
marks:add(0, 0, 0, 1, util.conceal())
84+
marks:add(0, 0, 0, 18, util.highlight('link'))
85+
marks:add(0, 0, 17, 18, util.conceal())
86+
util.assert_view(marks, { '󰀓 [email protected] Email' })
7487
end)
7588

7689
it('bare url', function()
77-
util.setup.text({ '- <http://www.github.com/> Bare URL' })
90+
util.setup.text({ '<http://www.github.com/> Bare URL' })
7891
local marks = util.marks()
79-
marks:add(0, 0, 0, 2, util.bullet(1))
80-
marks:add(0, nil, 2, nil, util.link('git'))
81-
marks:add(0, 0, 2, 3, util.conceal())
82-
marks:add(0, 0, 2, 26, util.highlight('link'))
83-
marks:add(0, 0, 25, 26, util.conceal())
84-
util.assert_view(marks, { '● 󰊤 http://www.github.com/ Bare URL' })
92+
marks:add(0, nil, 0, nil, util.link('git'))
93+
marks:add(0, 0, 0, 1, util.conceal())
94+
marks:add(0, 0, 0, 24, util.highlight('link'))
95+
marks:add(0, 0, 23, 24, util.conceal())
96+
util.assert_view(marks, { '󰊤 http://www.github.com/ Bare URL' })
8597
end)
8698

8799
it('youtube', function()
88100
util.setup.text({
89-
'- [Youtube Link](https://www.youtube.com/watch?v=dQw4w9WgXcQ)',
101+
'[Youtube Link](https://www.youtube.com/watch?v=dQw4w9WgXcQ)',
90102
})
91103
local marks = util.marks()
92-
marks:add(0, 0, 0, 2, util.bullet(1))
93-
marks:add(0, nil, 2, nil, util.link('youtube'))
94-
util.assert_view(marks, { '● 󰗃 Youtube Link' })
104+
marks:add(0, nil, 0, nil, util.link('youtube'))
105+
util.assert_view(marks, { '󰗃 Youtube Link' })
95106
end)
96107

97108
it('footnote', function()
98109
util.setup.text({
99-
'- Footnote Link [^1 Info]',
110+
'Footnote Link [^1 Info]',
100111
'[^1 Info]: Some Info',
101112
})
102113
local marks = util.marks()
103-
marks:add(0, 0, 0, 2, util.bullet(1))
104-
marks:add(0, 0, 16, 25, {
114+
marks:add(0, 0, 14, 23, {
105115
virt_text = { { '¹ ᴵⁿᶠᵒ', 'RmLink' } },
106116
virt_text_pos = 'inline',
107117
conceal = '',
@@ -112,7 +122,7 @@ describe('ad hoc', function()
112122
conceal = '',
113123
})
114124
util.assert_view(marks, {
115-
'Footnote Link ¹ ᴵⁿᶠᵒ',
125+
'Footnote Link ¹ ᴵⁿᶠᵒ',
116126
'¹ ᴵⁿᶠᵒ: Some Info',
117127
})
118128
end)

0 commit comments

Comments
 (0)