diff --git a/lua/noice/health.lua b/lua/noice/health.lua index 97dbdbb..99f37f6 100644 --- a/lua/noice/health.lua +++ b/lua/noice/health.lua @@ -3,6 +3,7 @@ local require = require("noice.util.lazy") local Util = require("noice.util") local Config = require("noice.config") local Lsp = require("noice.lsp") +local Treesitter = require("noice.text.treesitter") local M = {} @@ -118,7 +119,7 @@ function M.check(opts) end for _, lang in ipairs({ "vim", "regex", "lua", "bash", "markdown", "markdown_inline" }) do - if pcall(vim.treesitter.language.require_language, lang) then + if Treesitter.has_lang(lang) then log.ok("**TreeSitter " .. lang .. "** parser is installed") else log.warn( diff --git a/lua/noice/text/treesitter.lua b/lua/noice/text/treesitter.lua index 19dac37..99c7d74 100644 --- a/lua/noice/text/treesitter.lua +++ b/lua/noice/text/treesitter.lua @@ -19,7 +19,14 @@ function M.highlight_markdown(buf, injections) parser:parse() end +function M.get_lang(ft) + return vim.treesitter.language.get_lang and vim.treesitter.language.get_lang(ft) or ft +end + function M.has_lang(lang) + if vim.treesitter.language.get_lang then + return vim.treesitter.language.get_lang(lang) ~= nil + end return vim.treesitter.language.require_language(lang, nil, true) end @@ -30,11 +37,11 @@ end ---@param lang string treesitter language -- luacheck: no redefined function M.highlight(buf, ns, range, lang) + lang = M.get_lang(lang) + buf = (buf == 0 or buf == nil) and vim.api.nvim_get_current_buf() or buf vim.fn.bufload(buf) - vim.treesitter.language.require_language(lang) - -- we can't use a cached parser here since that could interfer with the existing parser of the buffer local LanguageTree = require("vim.treesitter.languagetree") local opts = { injections = { php = "", html = "" } }