Skip to content

Commit

Permalink
docs: recommend wrapping vim.treesitter.get_node in pcall
Browse files Browse the repository at this point in the history
  • Loading branch information
Saghen committed Dec 21, 2024
1 parent fbd133c commit 4d886b7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down

0 comments on commit 4d886b7

Please sign in to comment.