diff --git a/lua/CopilotChat/chat.lua b/lua/CopilotChat/chat.lua index ecfea7d6..8c1ce978 100644 --- a/lua/CopilotChat/chat.lua +++ b/lua/CopilotChat/chat.lua @@ -30,7 +30,11 @@ local function create_buf() local bufnr = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_name(bufnr, 'copilot-chat') vim.bo[bufnr].filetype = 'markdown' - vim.treesitter.start(bufnr, 'markdown') + vim.bo[bufnr].syntax = 'markdown' + local ok, parser = pcall(vim.treesitter.get_parser, bufnr, 'markdown') + if ok and parser then + vim.treesitter.start(bufnr, 'markdown') + end return bufnr end diff --git a/lua/CopilotChat/health.lua b/lua/CopilotChat/health.lua index a9cdf58f..70d8aebb 100644 --- a/lua/CopilotChat/health.lua +++ b/lua/CopilotChat/health.lua @@ -30,6 +30,14 @@ local function lualib_installed(lib_name) return res end +--- Check if a treesitter parser is available +---@param ft string +---@return boolean +local function treesitter_parser_available(ft) + local res, parser = pcall(vim.treesitter.get_parser, 0, ft) + return res and parser ~= nil +end + function M.check() start('CopilotChat.nvim [core]') @@ -58,8 +66,7 @@ function M.check() start('CopilotChat.nvim [dependencies]') - local has_plenary = lualib_installed('plenary') - if has_plenary then + if lualib_installed('plenary') then ok('plenary: installed') else error('plenary: missing, required for running tests. Install plenary.nvim') @@ -74,11 +81,24 @@ function M.check() 'copilot: missing, required for 2 factor authentication. Install copilot.vim or copilot.lua' ) end + if lualib_installed('tiktoken_core') then ok('tiktoken_core: installed') else warn('tiktoken_core: missing, optional for token counting.') end + + if treesitter_parser_available('markdown') then + ok('treesitter[markdown]: installed') + else + warn('treesitter[markdown]: missing, optional for better chat highlighting') + end + + if treesitter_parser_available('diff') then + ok('treesitter[diff]: installed') + else + warn('treesitter[diff]: missing, optional for better diff highlighting') + end end return M