Skip to content

Commit 8d14528

Browse files
feat: Check highlight enabled per language in healthcheck
## Details Rather than checking if the highlight module is enabled for treesitter check that each language is individually enabled. This should hanlde cases like this: #89 Minor refactor, standardize on `function M.method` instead of `M.method = function`. Used both in a few places, better to stick to one.
1 parent a8a3577 commit 8d14528

17 files changed

+107
-99
lines changed

Diff for: doc/render-markdown.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 July 24
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 July 25
22

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

Diff for: lua/render-markdown/colors.lua

+7-3
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,17 @@ end
6464
---@param foreground string
6565
---@param background string
6666
---@return string
67-
M.combine = function(foreground, background)
67+
function M.combine(foreground, background)
6868
local name = string.format('%s_%s_%s', M.prefix, foreground, background)
6969
if not vim.tbl_contains(cache.highlights, name) then
7070
local fg = M.get_hl(foreground)
7171
local bg = M.get_hl(background)
7272
vim.api.nvim_set_hl(0, name, {
7373
fg = fg.fg,
7474
bg = bg.bg,
75+
---@diagnostic disable-next-line: undefined-field
7576
ctermfg = fg.ctermfg,
77+
---@diagnostic disable-next-line: undefined-field
7678
ctermbg = bg.ctermbg,
7779
})
7880
table.insert(cache.highlights, name)
@@ -82,14 +84,16 @@ end
8284

8385
---@param highlight string
8486
---@return string
85-
M.inverse = function(highlight)
87+
function M.inverse(highlight)
8688
local name = string.format('%s_Inverse_%s', M.prefix, highlight)
8789
if not vim.tbl_contains(cache.highlights, name) then
8890
local hl = M.get_hl(highlight)
8991
vim.api.nvim_set_hl(0, name, {
9092
fg = hl.bg,
9193
bg = hl.fg,
94+
---@diagnostic disable-next-line: undefined-field
9295
ctermbg = hl.ctermfg,
96+
---@diagnostic disable-next-line: undefined-field
9397
ctermfg = hl.ctermbg,
9498
})
9599
table.insert(cache.highlights, name)
@@ -100,7 +104,7 @@ end
100104
---@private
101105
---@param name string
102106
---@return vim.api.keyset.hl_info
103-
M.get_hl = function(name)
107+
function M.get_hl(name)
104108
return vim.api.nvim_get_hl(0, { name = name, link = false })
105109
end
106110

Diff for: lua/render-markdown/component.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local M = {}
1010
---@param text string
1111
---@param comparison 'exact'|'contains'
1212
---@return render.md.Component?
13-
M.callout = function(text, comparison)
13+
function M.callout(text, comparison)
1414
---@param callout render.md.CustomComponent
1515
---@return boolean
1616
local function matches(callout)
@@ -33,7 +33,7 @@ end
3333
---@param text string
3434
---@param comparison 'exact'|'starts'
3535
---@return render.md.Component?
36-
M.checkbox = function(text, comparison)
36+
function M.checkbox(text, comparison)
3737
---@param checkbox render.md.CustomComponent
3838
---@return boolean
3939
local function matches(checkbox)

Diff for: lua/render-markdown/handler/latex.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ local M = {}
1616
---@param root TSNode
1717
---@param buf integer
1818
---@return render.md.Mark[]
19-
M.parse = function(root, buf)
19+
function M.parse(root, buf)
2020
local latex = state.config.latex
2121
if not latex.enabled then
2222
return {}

Diff for: lua/render-markdown/handler/markdown.lua

+14-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local M = {}
1515
---@param root TSNode
1616
---@param buf integer
1717
---@return render.md.Mark[]
18-
M.parse = function(root, buf)
18+
function M.parse(root, buf)
1919
local marks = {}
2020
local query = state.markdown_query
2121
for id, node in query:iter_captures(root, buf) do
@@ -59,7 +59,7 @@ end
5959
---@param buf integer
6060
---@param info render.md.NodeInfo
6161
---@return render.md.Mark[]
62-
M.render_heading = function(buf, info)
62+
function M.render_heading(buf, info)
6363
local heading = state.config.heading
6464
if not heading.enabled then
6565
return {}
@@ -134,7 +134,7 @@ end
134134
---@param buf integer
135135
---@param info render.md.NodeInfo
136136
---@return render.md.Mark?
137-
M.render_dash = function(buf, info)
137+
function M.render_dash(buf, info)
138138
local dash = state.config.dash
139139
if not dash.enabled then
140140
return nil
@@ -164,7 +164,7 @@ end
164164
---@param buf integer
165165
---@param info render.md.NodeInfo
166166
---@return render.md.Mark[]
167-
M.render_code = function(buf, info)
167+
function M.render_code(buf, info)
168168
local code = state.config.code
169169
if not code.enabled or code.style == 'none' then
170170
return {}
@@ -289,7 +289,7 @@ end
289289
---@param info render.md.NodeInfo
290290
---@param code_block render.md.NodeInfo
291291
---@return render.md.Mark[]
292-
M.render_language = function(buf, info, code_block)
292+
function M.render_language(buf, info, code_block)
293293
local code = state.config.code
294294
if not vim.tbl_contains({ 'language', 'full' }, code.style) then
295295
return {}
@@ -336,7 +336,7 @@ end
336336
---@param buf integer
337337
---@param info render.md.NodeInfo
338338
---@return render.md.Mark[]
339-
M.render_list_marker = function(buf, info)
339+
function M.render_list_marker(buf, info)
340340
---@return boolean
341341
local function sibling_checkbox()
342342
if not state.config.checkbox.enabled then
@@ -418,7 +418,7 @@ end
418418
---@param info render.md.NodeInfo
419419
---@param checkbox_state render.md.CheckboxComponent
420420
---@return render.md.Mark?
421-
M.render_checkbox = function(info, checkbox_state)
421+
function M.render_checkbox(info, checkbox_state)
422422
local checkbox = state.config.checkbox
423423
if not checkbox.enabled then
424424
return nil
@@ -441,7 +441,7 @@ end
441441
---@param info render.md.NodeInfo
442442
---@param block_quote render.md.NodeInfo
443443
---@return render.md.Mark?
444-
M.render_quote_marker = function(info, block_quote)
444+
function M.render_quote_marker(info, block_quote)
445445
local quote = state.config.quote
446446
if not quote.enabled then
447447
return nil
@@ -471,7 +471,7 @@ end
471471
---@param text string?
472472
---@param highlight string
473473
---@return render.md.Mark?
474-
M.render_sign = function(buf, info, text, highlight)
474+
function M.render_sign(buf, info, text, highlight)
475475
local sign = state.config.sign
476476
if not sign.enabled or text == nil then
477477
return nil
@@ -497,7 +497,7 @@ end
497497
---@param buf integer
498498
---@param info render.md.NodeInfo
499499
---@return render.md.Mark[]
500-
M.render_table = function(buf, info)
500+
function M.render_table(buf, info)
501501
local pipe_table = state.config.pipe_table
502502
if not pipe_table.enabled or pipe_table.style == 'none' then
503503
return {}
@@ -534,7 +534,7 @@ end
534534
---@private
535535
---@param row render.md.NodeInfo
536536
---@return render.md.Mark
537-
M.render_table_delimiter = function(row)
537+
function M.render_table_delimiter(row)
538538
local pipe_table = state.config.pipe_table
539539
local border = pipe_table.border
540540
-- Order matters here, in particular handling inner intersections before left & right
@@ -563,7 +563,7 @@ end
563563
---@param row render.md.NodeInfo
564564
---@param highlight string
565565
---@return render.md.Mark
566-
M.render_table_row = function(buf, row, highlight)
566+
function M.render_table_row(buf, row, highlight)
567567
local pipe_table = state.config.pipe_table
568568
local marks = {}
569569
if vim.tbl_contains({ 'raw', 'padded' }, pipe_table.cell) then
@@ -629,7 +629,7 @@ end
629629
---@param first? render.md.NodeInfo
630630
---@param last? render.md.NodeInfo
631631
---@return render.md.Mark[]
632-
M.render_table_full = function(buf, delim, first, last)
632+
function M.render_table_full(buf, delim, first, last)
633633
local pipe_table = state.config.pipe_table
634634
local border = pipe_table.border
635635
if delim == nil or first == nil or last == nil then
@@ -690,7 +690,7 @@ end
690690
---@param buf integer
691691
---@param info render.md.NodeInfo
692692
---@return integer
693-
M.table_visual_offset = function(buf, info)
693+
function M.table_visual_offset(buf, info)
694694
local result = ts.concealed(buf, info)
695695
local query = state.inline_link_query
696696
local tree = vim.treesitter.get_string_parser(info.text, 'markdown_inline')

Diff for: lua/render-markdown/handler/markdown_inline.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local M = {}
1313
---@param root TSNode
1414
---@param buf integer
1515
---@return render.md.Mark[]
16-
M.parse = function(root, buf)
16+
function M.parse(root, buf)
1717
local marks = {}
1818
local query = state.inline_query
1919
for id, node in query:iter_captures(root, buf) do
@@ -36,7 +36,7 @@ end
3636
---@private
3737
---@param info render.md.NodeInfo
3838
---@return render.md.Mark?
39-
M.render_code = function(info)
39+
function M.render_code(info)
4040
local code = state.config.code
4141
if not code.enabled then
4242
return nil
@@ -60,7 +60,7 @@ end
6060
---@private
6161
---@param info render.md.NodeInfo
6262
---@return render.md.Mark?
63-
M.render_callout = function(info)
63+
function M.render_callout(info)
6464
local callout = component.callout(info.text, 'exact')
6565
if callout ~= nil then
6666
if not state.config.quote.enabled then
@@ -109,7 +109,7 @@ end
109109
---@private
110110
---@param info render.md.NodeInfo
111111
---@return render.md.Mark?
112-
M.render_link = function(info)
112+
function M.render_link(info)
113113
local icon = shared.link_icon(info)
114114
if icon == nil then
115115
return nil

Diff for: lua/render-markdown/handler/shared.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local M = {}
88
---As a result table rendering needs to be painfully aware of this logic
99
---@param info render.md.NodeInfo
1010
---@return string?
11-
M.link_icon = function(info)
11+
function M.link_icon(info)
1212
local link = state.config.link
1313
if not link.enabled then
1414
return nil

Diff for: lua/render-markdown/health.lua

+20-16
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,13 @@ function M.check()
2323
local has_treesitter = pcall(require, 'nvim-treesitter')
2424
if has_treesitter then
2525
vim.health.ok('installed')
26-
27-
M.check_parser('markdown')
28-
M.check_parser('markdown_inline')
26+
for _, language in ipairs({ 'markdown', 'markdown_inline' }) do
27+
M.check_parser(language)
28+
M.check_highlight(language)
29+
end
2930
if latex.enabled then
3031
M.check_parser('latex', latex_advice)
3132
end
32-
33-
local highlight = require('nvim-treesitter.configs').get_module('highlight')
34-
if highlight ~= nil and highlight.enable then
35-
vim.health.ok('highlights enabled')
36-
else
37-
vim.health.error('highlights not enabled')
38-
end
3933
else
4034
vim.health.error('not installed')
4135
end
@@ -71,16 +65,26 @@ function M.version(minimum, recommended)
7165
end
7266
end
7367

74-
---@param name string
68+
---@param language string
7569
---@param advice string?
76-
function M.check_parser(name, advice)
70+
function M.check_parser(language, advice)
7771
local parsers = require('nvim-treesitter.parsers')
78-
if parsers.has_parser(name) then
79-
vim.health.ok(name .. ': parser installed')
72+
if parsers.has_parser(language) then
73+
vim.health.ok(language .. ': parser installed')
8074
elseif advice == nil then
81-
vim.health.error(name .. ': parser not installed')
75+
vim.health.error(language .. ': parser not installed')
76+
else
77+
vim.health.warn(language .. ': parser not installed', advice)
78+
end
79+
end
80+
81+
---@param language string
82+
function M.check_highlight(language)
83+
local configs = require('nvim-treesitter.configs')
84+
if configs.is_enabled('highlight', language, 0) then
85+
vim.health.ok(language .. ': highlight enabled')
8286
else
83-
vim.health.warn(name .. ': parser not installed', advice)
87+
vim.health.error(language .. ': highlight not enabled')
8488
end
8589
end
8690

Diff for: lua/render-markdown/icons.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local M = {}
77
---@param language string
88
---@return string?
99
---@return string?
10-
M.get = function(language)
10+
function M.get(language)
1111
if has_mini_icons then
1212
---@diagnostic disable-next-line: return-type-mismatch
1313
return mini_icons.get('filetype', language)

Diff for: lua/render-markdown/init.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ function M.setup(opts)
458458
end
459459

460460
---@param opts any
461-
M.command = function(opts)
461+
function M.command(opts)
462462
local args = opts.fargs
463463
if #args == 0 then
464464
M.enable()
@@ -477,15 +477,15 @@ M.command = function(opts)
477477
end
478478
end
479479

480-
M.enable = function()
480+
function M.enable()
481481
manager.set_all(true)
482482
end
483483

484-
M.disable = function()
484+
function M.disable()
485485
manager.set_all(false)
486486
end
487487

488-
M.toggle = function()
488+
function M.toggle()
489489
manager.set_all(not state.enabled)
490490
end
491491

0 commit comments

Comments
 (0)