Skip to content

Commit

Permalink
fix: crashes on lines with invalid syntax
Browse files Browse the repository at this point in the history
Fixes #397
  • Loading branch information
kwaszczuk authored and lewis6991 committed Feb 17, 2024
1 parent b90ac39 commit 23b699a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lua/treesitter-context/context.lua
Original file line number Diff line number Diff line change
@@ -14,6 +14,10 @@ local get_query = vim.treesitter.query.get or vim.treesitter.query.get_query
--- @return TSNode[]?
local function get_parent_nodes(langtree, range)
local tree = langtree:tree_for_range(range, { ignore_injections = true })
if tree == nil then
return
end

local n = tree:root():named_descendant_for_range(unpack(range))

local ret = {} --- @type TSNode[]
@@ -248,6 +252,10 @@ function M.get(bufnr, winid)
end

local parents = get_parent_nodes(langtree, line_range)
if parents == nil then
return
end

for j = #parents, 1, -1 do
local parent = parents[j]
local parent_start_row = parent:range()

0 comments on commit 23b699a

Please sign in to comment.