From 3bb6966e914611e66a64a9db69d18d98a03ff821 Mon Sep 17 00:00:00 2001 From: novenary Date: Sun, 23 Jun 2024 02:07:24 +0300 Subject: [PATCH] fix: check if buffer is loaded Fixes #455. --- lua/treesitter-context/context.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/treesitter-context/context.lua b/lua/treesitter-context/context.lua index 2dd24724..b57e100f 100644 --- a/lua/treesitter-context/context.lua +++ b/lua/treesitter-context/context.lua @@ -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