Skip to content

Commit e05a9f2

Browse files
committedFeb 12, 2025
refactor: remove error false in parser health check
## Details Removes `{ error = false }` from `vim.treesitter.get_parser` call. Not necessary since the call is wrapped in a `pcall` as is and the parameter will be removed in `0.12`. https://neovim.io/doc/user/treesitter.html#vim.treesitter.get_parser() ``` If no parser can be created, an error is thrown. Set opts.error = false to suppress this and return nil (and an error message) instead. WARNING: This behavior will become default in Nvim 0.12 and the option will be removed. ```
1 parent 6f31942 commit e05a9f2

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
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: 2025 February 07
1+
*render-markdown.txt* For 0.10.0 Last change: 2025 February 12
22

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

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

+12-22
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.2'
8+
M.version = '8.0.3'
99

1010
function M.check()
1111
M.start('version')
@@ -21,17 +21,15 @@ 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-
2824
local latex = state.get(0).latex
2925
local latex_advice = 'Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }'
3026

27+
M.start('treesitter')
28+
M.check_parser('markdown')
29+
M.check_parser('markdown_inline')
3130
if latex.enabled then
3231
M.check_parser('latex', latex_advice)
3332
end
34-
3533
M.check_highlight('markdown')
3634

3735
M.start('icons')
@@ -83,8 +81,7 @@ end
8381
---@param language string
8482
---@param advice? string
8583
function M.check_parser(language, advice)
86-
local has_parser, _ = pcall(vim.treesitter.get_parser, 0, language, { error = false })
87-
84+
local has_parser = pcall(vim.treesitter.get_parser, 0, language)
8885
if has_parser then
8986
vim.health.ok(language .. ': parser installed')
9087
elseif advice == nil then
@@ -95,25 +92,18 @@ function M.check_parser(language, advice)
9592
end
9693

9794
---@private
98-
---@param language string
99-
function M.check_highlight(language)
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
95+
---@param filetype string
96+
function M.check_highlight(filetype)
97+
-- As nvim-treesitter is removing module support it cannot be used to check
98+
-- if highlights are enabled, so we create a buffer and check the state
10599
local bufnr = vim.api.nvim_create_buf(false, true)
106-
107-
vim.bo[bufnr].filetype = language
108-
100+
vim.bo[bufnr].filetype = filetype
109101
local has_highlighter = vim.treesitter.highlighter.active[bufnr] ~= nil
110-
111102
vim.api.nvim_buf_delete(bufnr, { force = true })
112-
113103
if has_highlighter then
114-
vim.health.ok(language .. ': highlight enabled')
104+
vim.health.ok(filetype .. ': highlight enabled')
115105
else
116-
vim.health.error(language .. ': highlight not enabled')
106+
vim.health.error(filetype .. ': highlight not enabled')
117107
end
118108
end
119109

0 commit comments

Comments
 (0)
Please sign in to comment.