@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
5
5
local M = {}
6
6
7
7
--- @private
8
- M .version = ' 8.4.1 '
8
+ M .version = ' 8.4.2 '
9
9
10
10
function M .check ()
11
11
M .start (' version' )
@@ -22,15 +22,21 @@ function M.check()
22
22
end
23
23
24
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 ' )
25
+ local latex = config .latex
26
+ local html = config .html
27
27
28
28
M .start (' treesitter' )
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 )
33
- M .check_highlight (' markdown' )
29
+ M .parser (' markdown' , true )
30
+ M .highlights (' markdown' )
31
+ M .highlighter (' markdown' )
32
+ M .parser (' markdown_inline' , true )
33
+ M .highlights (' markdown_inline' )
34
+ if latex .enabled then
35
+ M .parser (' latex' , false )
36
+ end
37
+ if html .enabled then
38
+ M .parser (' html' , false )
39
+ end
34
40
35
41
M .start (' icons' )
36
42
local provider = Icons .name ()
@@ -41,12 +47,14 @@ function M.check()
41
47
end
42
48
43
49
M .start (' executables' )
44
- M .check_executable (latex .converter , latex .enabled , latex_advice )
50
+ if latex .enabled then
51
+ M .executable (latex .converter , M .disable (' latex' ))
52
+ end
45
53
46
54
M .start (' conflicts' )
47
- M .check_plugin (' headlines' )
48
- M .check_plugin (' markview' )
49
- M .check_plugin (' obsidian' , function (obsidian )
55
+ M .plugin (' headlines' )
56
+ M .plugin (' markview' )
57
+ M .plugin (' obsidian' , function (obsidian )
50
58
if obsidian .get_client ().opts .ui .enable == false then
51
59
return nil
52
60
else
@@ -77,69 +85,66 @@ function M.neovim(min, rec)
77
85
end
78
86
end
79
87
80
- --- @private
81
- --- @param language string
82
- --- @return string[]
83
- function M .disable_advice (language )
84
- local setup = " require('render-markdown').setup"
85
- return {
86
- (' disable %s support to avoid this warning' ):format (language ),
87
- (' %s({ %s = { enabled = false } })' ):format (setup , language ),
88
- }
89
- end
90
-
91
88
--- @private
92
89
--- @param language string
93
90
--- @param required boolean
94
- --- @param advice ? string[]
95
- function M .check_parser (language , required , advice )
96
- local has_parser = pcall (vim .treesitter .get_parser , 0 , language )
97
- if has_parser then
91
+ function M .parser (language , required )
92
+ local ok = pcall (vim .treesitter .get_parser , 0 , language )
93
+ if ok then
98
94
vim .health .ok (language .. ' : parser installed' )
99
95
else
100
96
local message = language .. ' : parser not installed'
101
97
if not required then
102
- vim .health .ok (message )
103
- elseif advice then
104
- vim .health .warn (message , advice )
98
+ vim .health .warn (message , M .disable (language ))
105
99
else
106
100
vim .health .error (message )
107
101
end
108
102
end
109
103
end
110
104
111
105
--- @private
112
- --- @param filetype string
113
- function M .check_highlight (filetype )
114
- -- As nvim-treesitter is removing module support it cannot be used to check
106
+ --- @param language string
107
+ function M .highlights (language )
108
+ local files = vim .treesitter .query .get_files (language , ' highlights' )
109
+ if # files > 0 then
110
+ for _ , file in ipairs (files ) do
111
+ local path = vim .fn .fnamemodify (file , ' :~' )
112
+ vim .health .ok (language .. ' : highlights ' .. path )
113
+ end
114
+ else
115
+ vim .health .error (language .. ' : highlights missing' )
116
+ end
117
+ end
118
+
119
+ --- @private
120
+ --- @param language string
121
+ function M .highlighter (language )
122
+ -- nvim-treesitter is removing module support so cannot be used to check
115
123
-- if highlights are enabled, so we create a buffer and check the state
116
- local bufnr = vim .api .nvim_create_buf (false , true )
117
- vim .bo [bufnr ].filetype = filetype
118
- local has_highlighter = vim .treesitter .highlighter .active [bufnr ] ~= nil
119
- vim .api .nvim_buf_delete (bufnr , { force = true })
120
- if has_highlighter then
121
- vim .health .ok (filetype .. ' : highlight enabled' )
124
+ local buf = vim .api .nvim_create_buf (false , true )
125
+ vim .bo [buf ].filetype = language
126
+ local ok = vim .treesitter .highlighter .active [buf ] ~= nil
127
+ vim .api .nvim_buf_delete (buf , { force = true })
128
+ if ok then
129
+ vim .health .ok (language .. ' : highlighter enabled' )
122
130
else
123
131
-- TODO(1.0): update advice once module support is removed
124
- vim .health .error (filetype .. ' : highlight not enabled' , {
125
- ' Enable the highlight module in your nvim-treesitter config' ,
132
+ vim .health .error (language .. ' : highlighter not enabled' , {
133
+ ' enable the highlight module in your nvim-treesitter config' ,
126
134
" require('nvim-treesitter.configs').setup({ highlight = { enable = true } })" ,
127
135
})
128
136
end
129
137
end
130
138
131
139
--- @private
132
140
--- @param name string
133
- --- @param required boolean
134
141
--- @param advice ? string[]
135
- function M .check_executable (name , required , advice )
142
+ function M .executable (name , advice )
136
143
if vim .fn .executable (name ) == 1 then
137
144
vim .health .ok (name .. ' : installed' )
138
145
else
139
146
local message = name .. ' : not installed'
140
- if not required then
141
- vim .health .ok (message )
142
- elseif advice then
147
+ if advice then
143
148
vim .health .warn (message , advice )
144
149
else
145
150
vim .health .error (message )
150
155
--- @private
151
156
--- @param name string
152
157
--- @param validate ? fun ( plugin : any ): string[] ?
153
- function M .check_plugin (name , validate )
158
+ function M .plugin (name , validate )
154
159
local has_plugin , plugin = pcall (require , name )
155
160
if not has_plugin then
156
161
vim .health .ok (name .. ' : not installed' )
@@ -166,4 +171,15 @@ function M.check_plugin(name, validate)
166
171
end
167
172
end
168
173
174
+ --- @private
175
+ --- @param language string
176
+ --- @return string[]
177
+ function M .disable (language )
178
+ local setup = " require('render-markdown').setup"
179
+ return {
180
+ (' disable %s support to avoid this warning' ):format (language ),
181
+ (' %s({ %s = { enabled = false } })' ):format (setup , language ),
182
+ }
183
+ end
184
+
169
185
return M
0 commit comments