Skip to content

Commit d4e4355

Browse files
author
Andrew Ferrier
committed
fix: Handle not finding node
1 parent 1474cae commit d4e4355

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lua/debugprint/init.lua

+9-4
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,18 @@ local find_treesitter_variable = function()
7474
-- Once get_node_at_cursor() is in NeoVim core, the nvim-treesitter
7575
-- dependency can be removed: https://github.com/neovim/neovim/pull/18232
7676
local node = ts_utils.get_node_at_cursor()
77-
local node_type = node:type()
78-
local variable_name = vim.treesitter.query.get_node_text(node, 0)
7977

80-
if node_type ~= "identifier" then
78+
if node == nil then
8179
return nil
8280
else
83-
return variable_name
81+
local node_type = node:type()
82+
local variable_name = vim.treesitter.query.get_node_text(node, 0)
83+
84+
if node_type ~= "identifier" then
85+
return nil
86+
else
87+
return variable_name
88+
end
8489
end
8590
end
8691
end

0 commit comments

Comments
 (0)