From 4d886b720ade88470617cc4d369eeb4476ce0140 Mon Sep 17 00:00:00 2001 From: Liam Dyer Date: Sat, 21 Dec 2024 14:53:15 -0500 Subject: [PATCH] docs: recommend wrapping vim.treesitter.get_node in pcall --- docs/recipes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/recipes.md b/docs/recipes.md index 594339cf..911587a3 100644 --- a/docs/recipes.md +++ b/docs/recipes.md @@ -106,10 +106,10 @@ vim.api.nvim_create_autocmd('User', { ```lua sources.default = function(ctx) - local node = vim.treesitter.get_node() + local success, node = pcall(vim.treesitter.get_node) if vim.bo.filetype == 'lua' then return { 'lsp', 'path' } - elseif node and vim.tbl_contains({ 'comment', 'line_comment', 'block_comment' }, node:type()) then + elseif success and node and vim.tbl_contains({ 'comment', 'line_comment', 'block_comment' }, node:type()) then return { 'buffer' } else return { 'lsp', 'path', 'snippets', 'buffer' }