Skip to content

Commit 00d0fb3

Browse files
authored
fix(chat): automatically start treesitter if not started (#1410)
As treesitter is now a requirement, it needs to be started automatically. nvim-treesitter does not auto start it anymore on latest branch so we need to do it ourselves. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent a88874e commit 00d0fb3

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lua/CopilotChat/ui/chat.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ end
117117
---@field private separator string
118118
---@field private spinner CopilotChat.ui.spinner.Spinner
119119
---@field private chat_overlay CopilotChat.ui.overlay.Overlay
120+
---@field private last_changedtick number?
120121
local Chat = class(function(self, config, on_buf_create)
121122
Overlay.init(self, 'copilot-chat', utils.key_to_info('show_help', config.mappings.show_help), on_buf_create)
122123

@@ -616,6 +617,12 @@ function Chat:create()
616617
local bufnr = Overlay.create(self)
617618
vim.bo[bufnr].syntax = 'markdown'
618619
vim.bo[bufnr].textwidth = 0
620+
vim.bo[bufnr].undolevels = 10
621+
self.spinner.bufnr = bufnr
622+
623+
vim.schedule(function()
624+
pcall(vim.treesitter.start, bufnr)
625+
end)
619626

620627
vim.api.nvim_create_autocmd({ 'TextChanged', 'InsertLeave' }, {
621628
buffer = bufnr,
@@ -627,7 +634,6 @@ function Chat:create()
627634
end,
628635
})
629636

630-
self.spinner.bufnr = bufnr
631637
return bufnr
632638
end
633639

@@ -647,10 +653,10 @@ function Chat:parse()
647653

648654
-- Skip parsing if buffer hasn't changed
649655
local changedtick = vim.api.nvim_buf_get_changedtick(self.bufnr)
650-
if self._last_changedtick == changedtick then
656+
if self.last_changedtick == changedtick then
651657
return false
652658
end
653-
self._last_changedtick = changedtick
659+
self.last_changedtick = changedtick
654660

655661
local parser = vim.treesitter.get_parser(self.bufnr, 'markdown')
656662
if not parser then

0 commit comments

Comments
 (0)