Skip to content

Commit

Permalink
fix: check if buffer is loaded
Browse files Browse the repository at this point in the history
Fixes #455.
  • Loading branch information
9ary authored and lewis6991 committed Jul 5, 2024
1 parent d176793 commit 3bb6966
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lua/treesitter-context/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ end
--- @param winid integer
--- @return Range4[]?, string[]?
function M.get(bufnr, winid)
-- vim.treesitter.get_parser() calls bufload(), but we don't actually want to load the buffer:
-- this method is called during plugin init, before other plugins or the user's config
-- have a chance to initialize.
-- They may want to register autocmds, and this would prevent them from firing.
if not api.nvim_buf_is_loaded(bufnr) then
return
end

if not pcall(vim.treesitter.get_parser, bufnr) then
return
end
Expand Down

0 comments on commit 3bb6966

Please sign in to comment.