From d4e58f6a22ae424c9ade2146b29dc808a7e4c538 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 25 Feb 2025 17:34:23 +0800 Subject: [PATCH] feat(health): check treesitter dependency (#1392) --- lua/avante/health.lua | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/lua/avante/health.lua b/lua/avante/health.lua index a39787c..743032f 100644 --- a/lua/avante/health.lua +++ b/lua/avante/health.lua @@ -37,6 +37,61 @@ function M.check() H.error("Copilot provider is configured but neither copilot.lua nor copilot.vim is installed") end end + + -- Check TreeSitter dependencies + M.check_treesitter() +end + +-- Check TreeSitter functionality and parsers +function M.check_treesitter() + H.start("TreeSitter Dependencies") + + -- Check if TreeSitter is available + local has_ts, _ = pcall(require, "nvim-treesitter.configs") + if not has_ts then + H.error("TreeSitter not available. Make sure nvim-treesitter is properly installed") + return + end + + H.ok("TreeSitter core functionality is available") + + -- Check for essential parsers + local has_parsers, parsers = pcall(require, "nvim-treesitter.parsers") + if not has_parsers then + H.error("TreeSitter parsers module not available") + return + end + + -- List of important parsers for avante.nvim + local essential_parsers = { + "markdown", + } + + local missing_parsers = {} + + for _, parser in ipairs(essential_parsers) do + if parsers.has_parser and not parsers.has_parser(parser) then table.insert(missing_parsers, parser) end + end + + if #missing_parsers == 0 then + H.ok("All essential TreeSitter parsers are installed") + else + H.warn( + string.format( + "Missing recommended parsers: %s. Install with :TSInstall %s", + table.concat(missing_parsers, ", "), + table.concat(missing_parsers, " ") + ) + ) + end + + -- Check TreeSitter highlight + local _, highlighter = pcall(require, "vim.treesitter.highlighter") + if not highlighter then + H.warn("TreeSitter highlighter not available. Syntax highlighting might be limited") + else + H.ok("TreeSitter highlighter is available") + end end return M