Skip to content

Commit 6f31942

Browse files
authored
fix(health): update to not require nvim-treesitter (#322)
* fix(health): update to not require nvim-treesitter * add back buffer highlight check --------- Co-authored-by: Dan Sully <[email protected]>
1 parent 17a7746 commit 6f31942

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

lua/render-markdown/health.lua

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,19 @@ function M.check()
2121
vim.health.error(message)
2222
end
2323

24+
M.start('treesitter')
25+
M.check_parser('markdown')
26+
M.check_parser('markdown_inline')
27+
2428
local latex = state.get(0).latex
2529
local latex_advice = 'Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }'
2630

27-
M.start('nvim-treesitter')
28-
local has_treesitter = pcall(require, 'nvim-treesitter')
29-
if has_treesitter then
30-
vim.health.ok('installed')
31-
for _, language in ipairs({ 'markdown', 'markdown_inline' }) do
32-
M.check_parser(language)
33-
M.check_highlight(language)
34-
end
35-
if latex.enabled then
36-
M.check_parser('latex', latex_advice)
37-
end
38-
else
39-
vim.health.error('not installed')
31+
if latex.enabled then
32+
M.check_parser('latex', latex_advice)
4033
end
4134

35+
M.check_highlight('markdown')
36+
4237
M.start('icons')
4338
local provider = Icons.provider()
4439
if provider ~= nil then
@@ -88,8 +83,9 @@ end
8883
---@param language string
8984
---@param advice? string
9085
function M.check_parser(language, advice)
91-
local parsers = require('nvim-treesitter.parsers')
92-
if parsers.has_parser(language) then
86+
local has_parser, _ = pcall(vim.treesitter.get_parser, 0, language, { error = false })
87+
88+
if has_parser then
9389
vim.health.ok(language .. ': parser installed')
9490
elseif advice == nil then
9591
vim.health.error(language .. ': parser not installed')
@@ -101,8 +97,20 @@ end
10197
---@private
10298
---@param language string
10399
function M.check_highlight(language)
104-
local configs = require('nvim-treesitter.configs')
105-
if configs.is_enabled('highlight', language, 0) then
100+
--
101+
-- As the markdown parser is part of Neovim, and nvim-treesitter no longer provides
102+
-- .is_enabled() for the main branch, create a markdown buffer and check the state.
103+
--
104+
-- See: https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/322#discussion_r1947393569
105+
local bufnr = vim.api.nvim_create_buf(false, true)
106+
107+
vim.bo[bufnr].filetype = language
108+
109+
local has_highlighter = vim.treesitter.highlighter.active[bufnr] ~= nil
110+
111+
vim.api.nvim_buf_delete(bufnr, { force = true })
112+
113+
if has_highlighter then
106114
vim.health.ok(language .. ': highlight enabled')
107115
else
108116
vim.health.error(language .. ': highlight not enabled')

0 commit comments

Comments
 (0)