Skip to content

Commit 1ef7664

Browse files
feat: improve checkhealth
## Details - check for `html` parser if `html` configuration is not disabled - always make the same checks, but take into account whether that thing is required, rather than avoiding the check entirely - add `markview.nvim` as a conflicting plugin - other unrelated minor refactor changes, nothing functionally different
1 parent 595ac4f commit 1ef7664

File tree

12 files changed

+82
-63
lines changed

12 files changed

+82
-63
lines changed

benches/util.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ end
5454

5555
---@param expected integer
5656
function M.num_marks(expected)
57-
local namespace = require('render-markdown.core.ui').namespace
58-
local marks = vim.api.nvim_buf_get_extmarks(0, namespace, 0, -1, {})
57+
local ui = require('render-markdown.core.ui')
58+
local marks = vim.api.nvim_buf_get_extmarks(0, ui.ns, 0, -1, {})
5959
assert.are.same(expected, #marks)
6060
end
6161

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: 2025 February 28
1+
*render-markdown.txt* For 0.10.0 Last change: 2025 March 02
22

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

lua/render-markdown/core/extmark.lua

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,35 @@ function Extmark.new(mark)
1414
end
1515

1616
---@return render.md.Mark
17-
function Extmark:get_mark()
17+
function Extmark:get()
1818
return self.mark
1919
end
2020

21-
---@param ns_id integer
21+
---@param range? render.md.Range
22+
---@return boolean
23+
function Extmark:inside(range)
24+
if range == nil then
25+
return false
26+
end
27+
local row = self.mark.start_row
28+
return range:contains(row, row)
29+
end
30+
31+
---@param ns integer
2232
---@param buf integer
23-
function Extmark:show(ns_id, buf)
33+
function Extmark:show(ns, buf)
2434
if self.id == nil then
2535
local mark = self.mark
2636
mark.opts.strict = false
27-
self.id = vim.api.nvim_buf_set_extmark(buf, ns_id, mark.start_row, mark.start_col, mark.opts)
37+
self.id = vim.api.nvim_buf_set_extmark(buf, ns, mark.start_row, mark.start_col, mark.opts)
2838
end
2939
end
3040

31-
---@param ns_id integer
41+
---@param ns integer
3242
---@param buf integer
33-
function Extmark:hide(ns_id, buf)
43+
function Extmark:hide(ns, buf)
3444
if self.id ~= nil then
35-
vim.api.nvim_buf_del_extmark(buf, ns_id, self.id)
45+
vim.api.nvim_buf_del_extmark(buf, ns, self.id)
3646
self.id = nil
3747
end
3848
end

lua/render-markdown/core/ui.lua

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ end
3434
---@class render.md.Ui
3535
local M = {}
3636

37-
M.namespace = vim.api.nvim_create_namespace('render-markdown.nvim')
37+
M.ns = vim.api.nvim_create_namespace('render-markdown.nvim')
3838

3939
function M.invalidate_cache()
4040
for buf, buffer_state in pairs(Cache.states) do
@@ -54,9 +54,8 @@ function M.get_row_marks(buf, win)
5454

5555
local marks = {}
5656
for _, extmark in ipairs(buffer_state:get_marks()) do
57-
local mark = extmark:get_mark()
58-
if hidden:contains(mark.start_row, mark.start_row) then
59-
table.insert(marks, mark)
57+
if extmark:inside(hidden) then
58+
table.insert(marks, extmark:get())
6059
end
6160
end
6261
return row, marks
@@ -66,7 +65,7 @@ end
6665
---@param buf integer
6766
---@param buffer_state render.md.BufferState
6867
function M.clear(buf, buffer_state)
69-
vim.api.nvim_buf_clear_namespace(buf, M.namespace, 0, -1)
68+
vim.api.nvim_buf_clear_namespace(buf, M.ns, 0, -1)
7069
buffer_state:set_marks(nil)
7170
end
7271

@@ -142,11 +141,10 @@ function M.run_update(buf, win, change)
142141
local hidden = config:hidden(mode, row)
143142
local extmarks = buffer_state:get_marks()
144143
for _, extmark in ipairs(extmarks) do
145-
local mark = extmark:get_mark()
146-
if mark.conceal and hidden ~= nil and hidden:contains(mark.start_row, mark.start_row) then
147-
extmark:hide(M.namespace, buf)
144+
if extmark:get().conceal and extmark:inside(hidden) then
145+
extmark:hide(M.ns, buf)
148146
else
149-
extmark:show(M.namespace, buf)
147+
extmark:show(M.ns, buf)
150148
end
151149
end
152150
state.on.render({ buf = buf })

lua/render-markdown/handler/latex.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function M.parse(ctx)
4848
table.insert(expressions, '')
4949
end
5050

51-
local latex_lines = Iter.list.map(expressions, function(expression)
51+
local lines = Iter.list.map(expressions, function(expression)
5252
return { { expression, latex.highlight } }
5353
end)
5454

@@ -57,7 +57,7 @@ function M.parse(ctx)
5757

5858
local marks = List.new_marks(ctx.buf, true)
5959
marks:add(false, row, 0, {
60-
virt_lines = latex_lines,
60+
virt_lines = lines,
6161
virt_lines_above = above,
6262
})
6363
return marks:get()

lua/render-markdown/health.lua

Lines changed: 42 additions & 23 deletions
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.0.14'
8+
M.version = '8.0.15'
99

1010
function M.check()
1111
M.start('version')
@@ -21,15 +21,15 @@ function M.check()
2121
vim.health.error(message)
2222
end
2323

24-
local latex = state.get(0).latex
25-
local latex_advice = 'Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }'
24+
local config = state.get(0)
25+
local latex, latex_advice = config.latex, M.disable_advice('latex')
26+
local html, html_advice = config.html, M.disable_advice('html')
2627

2728
M.start('treesitter')
28-
M.check_parser('markdown')
29-
M.check_parser('markdown_inline')
30-
if latex.enabled then
31-
M.check_parser('latex', latex_advice)
32-
end
29+
M.check_parser('markdown', true)
30+
M.check_parser('markdown_inline', true)
31+
M.check_parser('latex', latex.enabled, latex_advice)
32+
M.check_parser('html', html.enabled, html_advice)
3333
M.check_highlight('markdown')
3434

3535
M.start('icons')
@@ -41,14 +41,11 @@ function M.check()
4141
end
4242

4343
M.start('executables')
44-
if latex.enabled then
45-
M.check_executable(latex.converter, latex_advice)
46-
else
47-
vim.health.ok('none to check')
48-
end
44+
M.check_executable(latex.converter, latex.enabled, latex_advice)
4945

5046
M.start('conflicts')
5147
M.check_plugin('headlines')
48+
M.check_plugin('markview')
5249
M.check_plugin('obsidian', function(obsidian)
5350
if obsidian.get_client().opts.ui.enable == false then
5451
return nil
@@ -79,15 +76,31 @@ end
7976

8077
---@private
8178
---@param language string
82-
---@param advice? string
83-
function M.check_parser(language, advice)
79+
---@return string[]
80+
function M.disable_advice(language)
81+
return {
82+
string.format('Disable %s support to avoid this warning', language),
83+
string.format('Set { %s = { enabled = false } }', language),
84+
}
85+
end
86+
87+
---@private
88+
---@param language string
89+
---@param required boolean
90+
---@param advice? string[]
91+
function M.check_parser(language, required, advice)
8492
local has_parser = pcall(vim.treesitter.get_parser, 0, language)
8593
if has_parser then
8694
vim.health.ok(language .. ': parser installed')
87-
elseif advice == nil then
88-
vim.health.error(language .. ': parser not installed')
8995
else
90-
vim.health.warn(language .. ': parser not installed', advice)
96+
local message = language .. ': parser not installed'
97+
if not required then
98+
vim.health.ok(message)
99+
elseif advice ~= nil then
100+
vim.health.warn(message, advice)
101+
else
102+
vim.health.error(message)
103+
end
91104
end
92105
end
93106

@@ -109,14 +122,20 @@ end
109122

110123
---@private
111124
---@param name string
112-
---@param advice? string
113-
function M.check_executable(name, advice)
125+
---@param required boolean
126+
---@param advice? string[]
127+
function M.check_executable(name, required, advice)
114128
if vim.fn.executable(name) == 1 then
115129
vim.health.ok(name .. ': installed')
116-
elseif advice == nil then
117-
vim.health.error(name .. ': not installed')
118130
else
119-
vim.health.warn(name .. ': not installed', advice)
131+
local message = name .. ': not installed'
132+
if not required then
133+
vim.health.ok(message)
134+
elseif advice ~= nil then
135+
vim.health.warn(message, advice)
136+
else
137+
vim.health.error(message)
138+
end
120139
end
121140
end
122141

lua/render-markdown/lib/list.lua

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ function Marks:get()
2929
return self.marks
3030
end
3131

32-
---@param element boolean|render.md.Element
33-
---@param node render.md.Node
34-
---@param opts vim.api.keyset.set_extmark
35-
---@return boolean
36-
function Marks:add_start(element, node, opts)
37-
return self:add(element, node.start_row, node.start_col, opts)
38-
end
39-
4032
---@param element boolean|render.md.Element
4133
---@param node render.md.Node
4234
---@param opts vim.api.keyset.set_extmark

lua/render-markdown/render/base.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function Base:sign(text, highlight)
4444
if highlight ~= nil then
4545
sign_highlight = colors.combine(highlight, sign_highlight)
4646
end
47-
self.marks:add_start('sign', self.node, {
47+
self.marks:add('sign', self.node.start_row, self.node.start_col, {
4848
sign_text = text,
4949
sign_hl_group = sign_highlight,
5050
})
@@ -137,7 +137,7 @@ end
137137

138138
---@protected
139139
---@param width integer
140-
---@param highlight? string
140+
---@param highlight? string|string[]
141141
---@return render.md.line.Text
142142
function Base:pad(width, highlight)
143143
return { Str.pad(width), highlight or self.config.padding.highlight }

lua/render-markdown/render/code.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ function Render:language()
129129
self:sign(icon, icon_highlight)
130130
end
131131

132-
local text = icon .. ' '
133-
local highlight = { icon_highlight }
132+
local text, highlight = icon .. ' ', { icon_highlight }
134133
if self.code.border ~= 'none' then
135134
table.insert(highlight, self.code.highlight)
136135
end
@@ -140,10 +139,11 @@ function Render:language()
140139
-- Code blocks pick up varying amounts of leading white space depending
141140
-- on the context they are in. This is lumped into the delimiter node
142141
-- and as a result, after concealing, the extmark would be shifted.
143-
local padding = Str.spaces('start', self.node.text) + self.data.language_padding
144-
text = Str.pad(padding) .. text .. node.text
142+
local spaces = Str.spaces('start', self.node.text)
143+
local padding = Str.pad(spaces + self.data.language_padding)
144+
text = padding .. text .. node.text
145145
end
146-
return self.marks:add_start('code_language', node, {
146+
return self.marks:add('code_language', node.start_row, node.start_col, {
147147
virt_text = { { text, highlight } },
148148
virt_text_pos = 'inline',
149149
})

lua/render-markdown/render/html_tag.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222
function Render:render()
2323
self:hide('start_tag')
2424
self:hide('end_tag')
25-
self.marks:add_start(false, self.node, {
25+
self.marks:add(false, self.node.start_row, self.node.start_col, {
2626
virt_text = { { self.tag.icon, self.tag.highlight } },
2727
virt_text_pos = 'inline',
2828
})

lua/render-markdown/render/table.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ function Render:full()
378378
local line = spaces > 0 and { self:pad(spaces) } or {}
379379
local highlight = above and self.table.head or self.table.row
380380
table.insert(line, { chars[1] .. table.concat(sections, chars[2]) .. chars[3], highlight })
381-
self.marks:add_start(false, node, {
381+
self.marks:add(false, node.start_row, node.start_col, {
382382
virt_lines = { vim.list_extend(self:indent_line(true), line) },
383383
virt_lines_above = above,
384384
})

tests/util.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ end
472472
---@private
473473
---@return render.md.MarkInfo[]
474474
function M.actual_marks()
475-
local namespace = require('render-markdown.core.ui').namespace
476-
local marks = vim.api.nvim_buf_get_extmarks(0, namespace, 0, -1, { details = true })
475+
local ui = require('render-markdown.core.ui')
476+
local marks = vim.api.nvim_buf_get_extmarks(0, ui.ns, 0, -1, { details = true })
477477
---@type render.md.MarkDetails[]
478478
local actual = {}
479479
for _, mark in ipairs(marks) do

0 commit comments

Comments
 (0)