Skip to content

Commit 43ab634

Browse files
chore(refactor): get config in mark list, configure context update
## Details In list of marks fetch config from state module directly rather than having it passed as a parameter. Add a parameter of whether to update context, which we should do in all handlers except for the main markdown handler. This avoids adding offset and conceal values that we can't practically use. Minor other changes: - Use assert calls from luassert directly when needed - Inline require ui to get namespace in test utils
1 parent d6a82d7 commit 43ab634

File tree

11 files changed

+35
-37
lines changed

11 files changed

+35
-37
lines changed

benches/util.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
---@module 'luassert'
22

3-
local ui = require('render-markdown.core.ui')
4-
local eq = assert.are.same
5-
local truthy = assert.truthy
6-
73
---@class render.md.bench.Util
84
local M = {}
95

@@ -53,13 +49,14 @@ end
5349
---@param actual number
5450
---@param max number
5551
function M.less_than(actual, max)
56-
truthy(actual < max, string.format('expected %f < %f', actual, max))
52+
assert.truthy(actual < max, string.format('expected %f < %f', actual, max))
5753
end
5854

5955
---@param expected integer
6056
function M.num_marks(expected)
61-
local marks = vim.api.nvim_buf_get_extmarks(0, ui.namespace, 0, -1, {})
62-
eq(expected, #marks)
57+
local namespace = require('render-markdown.core.ui').namespace
58+
local marks = vim.api.nvim_buf_get_extmarks(0, namespace, 0, -1, {})
59+
assert.are.same(expected, #marks)
6360
end
6461

6562
return M

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.10.0 Last change: 2024 November 20
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 November 22
22

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

lua/render-markdown/handler/latex.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function M.parse(root, buf)
5252
return { { expression, latex.highlight } }
5353
end)
5454

55-
local marks = List.new_marks(buf, nil)
55+
local marks = List.new_marks(buf, true)
5656
marks:add_over(false, node, {
5757
virt_lines = latex_lines,
5858
virt_lines_above = true,

lua/render-markdown/handler/markdown.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Handler.new(buf)
1818
local self = setmetatable({}, Handler)
1919
self.config = state.get(buf)
2020
self.context = Context.get(buf)
21-
self.marks = List.new_marks(buf, self.config.anti_conceal.ignore)
21+
self.marks = List.new_marks(buf, false)
2222
self.query = treesitter.parse(
2323
'markdown',
2424
[[

lua/render-markdown/handler/markdown_inline.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Handler.new(buf)
1818
local self = setmetatable({}, Handler)
1919
self.config = state.get(buf)
2020
self.context = Context.get(buf)
21-
self.marks = List.new_marks(buf, self.config.anti_conceal.ignore)
21+
self.marks = List.new_marks(buf, true)
2222
self.query = treesitter.parse(
2323
'markdown_inline',
2424
[[

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.5.9'
7+
M.version = '7.5.10'
88

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

lua/render-markdown/lib/list.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
local Context = require('render-markdown.core.context')
22
local Str = require('render-markdown.lib.str')
33
local log = require('render-markdown.core.log')
4+
local state = require('render-markdown.state')
45
local util = require('render-markdown.core.util')
56

67
---@class render.md.Marks
78
---@field private context render.md.Context
89
---@field private ignore render.md.config.conceal.Ignore
10+
---@field private update boolean
911
---@field private marks render.md.Mark[]
1012
local Marks = {}
1113
Marks.__index = Marks
1214

1315
---@param buf integer
14-
---@param ignore? render.md.config.conceal.Ignore
16+
---@param update boolean
1517
---@return render.md.Marks
16-
function Marks.new(buf, ignore)
18+
function Marks.new(buf, update)
1719
local self = setmetatable({}, Marks)
1820
self.context = Context.get(buf)
19-
self.ignore = ignore or {}
21+
self.ignore = state.get(buf).anti_conceal.ignore
22+
self.update = update
2023
self.marks = {}
2124
return self
2225
end
@@ -58,7 +61,9 @@ function Marks:add(element, start_row, start_col, opts)
5861
return false
5962
end
6063
log.add('debug', 'mark', mark)
61-
self:update_context(mark)
64+
if self.update then
65+
self:update_context(mark)
66+
end
6267
table.insert(self.marks, mark)
6368
return true
6469
end

lua/render-markdown/state.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ end
2525
---@param default_config render.md.Config
2626
---@param user_config render.md.UserConfig
2727
function M.setup(default_config, user_config)
28-
local config = vim.tbl_deep_extend('force', default_config, presets.get(user_config), user_config)
28+
local preset_config = presets.get(user_config)
29+
local config = vim.tbl_deep_extend('force', default_config, preset_config, user_config)
2930
-- Override settings that require neovim >= 0.10.0 and have compatible alternatives
3031
if not util.has_10 then
3132
config.code.position = 'right'

tests/latex_spec.lua

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
local stub = require('luassert.stub')
44
local util = require('tests.util')
5-
local eq = assert.are.same
6-
local truthy = assert.truthy
75

86
---@param start_row integer
97
---@param end_row integer
@@ -29,13 +27,13 @@ end
2927
---@param responses table<string, string>
3028
local function set_responses(converter, responses)
3129
stub.new(vim.fn, 'executable', function(expr)
32-
eq(converter, expr)
30+
assert.are.same(converter, expr)
3331
return 1
3432
end)
3533
stub.new(vim.fn, 'system', function(cmd, input)
36-
eq(converter, cmd)
34+
assert.are.same(converter, cmd)
3735
local result = responses[input]
38-
truthy(result, 'No output for: ' .. input)
36+
assert.truthy(result, 'No output for: ' .. input)
3937
return result
4038
end)
4139
end

tests/state_spec.lua

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---@module 'luassert'
22

33
local state = require('render-markdown.state')
4-
local eq = assert.are.same
54

65
---@param opts? render.md.UserConfig
76
---@return string[]
@@ -12,14 +11,14 @@ end
1211

1312
describe('state', function()
1413
it('valid', function()
15-
eq(0, #validate())
14+
assert.are.same(0, #validate())
1615
vim.bo.buftype = ''
17-
eq(true, state.get(0).sign.enabled)
16+
assert.are.same(true, state.get(0).sign.enabled)
1817
state.invalidate_cache()
1918
vim.bo.buftype = 'nofile'
20-
eq(false, state.get(0).sign.enabled)
19+
assert.are.same(false, state.get(0).sign.enabled)
2120

22-
eq(0, #validate({
21+
assert.are.same(0, #validate({
2322
callout = {
2423
note = { raw = 'value' },
2524
new = { raw = 'value', rendered = 'value', highlight = 'value' },
@@ -49,7 +48,7 @@ describe('state', function()
4948
end)
5049

5150
it('extra', function()
52-
eq(
51+
assert.are.same(
5352
{
5453
'render-markdown.additional: is not a valid key',
5554
'render-markdown.anti_conceal.ignore.additional: is not a valid key',
@@ -72,7 +71,7 @@ describe('state', function()
7271

7372
it('type', function()
7473
---@diagnostic disable: assign-type-mismatch
75-
eq(
74+
assert.are.same(
7675
{
7776
'render-markdown.anti_conceal.ignore.sign: expected string list or type boolean or nil, got string',
7877
'render-markdown.callout.a.highlight: expected type string, got nil',
@@ -118,7 +117,7 @@ describe('state', function()
118117
})
119118
)
120119

121-
eq(
120+
assert.are.same(
122121
{
123122
'render-markdown.checkbox: expected type table, got string',
124123
'render-markdown.render_modes: expected string list or type boolean, got table, info: [1] is number',

0 commit comments

Comments
 (0)