Skip to content

Commit

Permalink
Use get_node_at_position from Neovim 0.8 if available
Browse files Browse the repository at this point in the history
  • Loading branch information
kristijanhusak committed Sep 17, 2022
1 parent bf53c20 commit 7e42fdb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lua/orgmode/utils/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ end
---@param winnr? number
---@param ignore_injected_langs? boolean
function M.get_node_at_cursor(cursor, winnr, ignore_injected_langs)
if not cursor then
return ts_utils.get_node_at_cursor(winnr, ignore_injected_langs)
end

winnr = winnr or 0
cursor = cursor or vim.api.nvim_win_get_cursor(winnr)
local buf = vim.api.nvim_win_get_buf(winnr)
-- TODO: Use only this function when 0.8 is released
if vim.treesitter.get_node_at_position then
return vim.treesitter.get_node_at_position(buf, cursor[1] - 1, cursor[2], {
ignore_injections = ignore_injected_langs,
})
end

local cursor_range = { cursor[1] - 1, cursor[2] }

local buf = vim.api.nvim_win_get_buf(winnr)
local root_lang_tree = parsers.get_parser(buf)
if not root_lang_tree then
return
Expand Down

0 comments on commit 7e42fdb

Please sign in to comment.