Skip to content

Commit

Permalink
fix(treesitter): show warning for missing treesitter parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 30, 2024
1 parent f000daa commit 4253652
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 0 additions & 9 deletions lua/trouble/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,6 @@ function M.setup(opts)
error(msg)
return
end
if vim.fn.has("nvim-0.10.0") == 0 then
local ok = pcall(vim.treesitter.language.add, "markdown_inline") and pcall(vim.treesitter.language.add, "markdown")
if not ok then
local msg =
"trouble.nvim requires Neovim >= 0.10.0 or\nnvim-treesitter with the markdown and markdown_inline parser"
vim.notify_once(msg, vim.log.levels.ERROR, { title = "trouble.nvim" })
error(msg)
end
end
opts = opts or {}
opts.mode = nil
options = {}
Expand Down
8 changes: 7 additions & 1 deletion lua/trouble/view/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ function M.highlight(buf, lang, regions)
lang = lang or "markdown"
lang = lang == "markdown" and "markdown_inline" or lang
-- lang = "markdown_inline"
local parser = vim.treesitter.get_parser(buf, lang)
local ok, parser = pcall(vim.treesitter.get_parser, buf, lang)

if not ok then
local msg = "nvim-treesitter parser missing `" .. lang .. "`"
vim.notify_once(msg, vim.log.levels.WARN, { title = "trouble.nvim" })
return
end

---@diagnostic disable-next-line: invisible
parser:set_included_regions(regions)
Expand Down

0 comments on commit 4253652

Please sign in to comment.