Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions lua/render-markdown/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,19 @@ function M.check()
vim.health.error(message)
end

M.start('treesitter')
M.check_parser('markdown')
M.check_parser('markdown_inline')

local latex = state.get(0).latex
local latex_advice = 'Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }'

M.start('nvim-treesitter')
local has_treesitter = pcall(require, 'nvim-treesitter')
if has_treesitter then
vim.health.ok('installed')
for _, language in ipairs({ 'markdown', 'markdown_inline' }) do
M.check_parser(language)
M.check_highlight(language)
end
if latex.enabled then
M.check_parser('latex', latex_advice)
end
else
vim.health.error('not installed')
if latex.enabled then
M.check_parser('latex', latex_advice)
end

M.check_highlight('markdown')

M.start('icons')
local provider = Icons.provider()
if provider ~= nil then
Expand Down Expand Up @@ -88,8 +83,9 @@ end
---@param language string
---@param advice? string
function M.check_parser(language, advice)
local parsers = require('nvim-treesitter.parsers')
if parsers.has_parser(language) then
local has_parser, _ = pcall(vim.treesitter.get_parser, 0, language, { error = false })

if has_parser then
vim.health.ok(language .. ': parser installed')
elseif advice == nil then
vim.health.error(language .. ': parser not installed')
Expand All @@ -101,8 +97,20 @@ end
---@private
---@param language string
function M.check_highlight(language)
local configs = require('nvim-treesitter.configs')
if configs.is_enabled('highlight', language, 0) then
--
-- As the markdown parser is part of Neovim, and nvim-treesitter no longer provides
-- .is_enabled() for the main branch, create a markdown buffer and check the state.
--
-- See: https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/322#discussion_r1947393569
local bufnr = vim.api.nvim_create_buf(false, true)

vim.bo[bufnr].filetype = language

local has_highlighter = vim.treesitter.highlighter.active[bufnr] ~= nil

vim.api.nvim_buf_delete(bufnr, { force = true })

if has_highlighter then
vim.health.ok(language .. ': highlight enabled')
else
vim.health.error(language .. ': highlight not enabled')
Expand Down