Skip to content

Commit b141128

Browse files
committed
fix: get_node_at_cursor works again on 0.8.x - closes #64
1 parent 36d94b1 commit b141128

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

lua/debugprint/utils.lua

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
local M = {}
22

33
local get_node_at_cursor = function()
4-
local success, is_node = pcall(vim.treesitter.get_node)
5-
6-
-- This will fail if this language is not supported by Treesitter, e.g.
7-
-- Powershell/ps1
8-
if success then
9-
if is_node then
10-
-- Supported as of NeoVim 0.9?
11-
return vim.treesitter.get_node()
4+
if vim.fn.has("nvim-0.9.0") == 1 then
5+
local success, is_node = pcall(vim.treesitter.get_node)
6+
7+
-- This will fail if this language is not supported by Treesitter, e.g.
8+
-- Powershell/ps1
9+
if success and is_node then
10+
return is_node
1211
else
13-
local function requiref(module)
14-
require(module)
15-
end
16-
17-
local ts_utils_test = pcall(requiref, "nvim-treesitter.ts_utils")
18-
19-
if not ts_utils_test then
20-
return nil
21-
else
22-
local ts_utils = require("nvim-treesitter.ts_utils")
23-
return ts_utils.get_node_at_cursor()
24-
end
12+
return nil
2513
end
2614
else
27-
return nil
15+
local function requiref(module)
16+
require(module)
17+
end
18+
19+
local ts_utils_test = pcall(requiref, "nvim-treesitter.ts_utils")
20+
21+
if not ts_utils_test then
22+
return nil
23+
else
24+
local ts_utils = require("nvim-treesitter.ts_utils")
25+
return ts_utils.get_node_at_cursor()
26+
end
2827
end
2928
end
3029

0 commit comments

Comments
 (0)