Skip to content

Commit fe68c28

Browse files
committed
fix: handle treesitter get_parser failure
Closes #171
1 parent d11f271 commit fe68c28

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lua/blink/cmp/utils.lua

+9-1
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,21 @@ function utils.combine_markdown_lines(lines)
7979
return combined_lines
8080
end
8181

82+
--- Highlights the given range with treesitter with the given filetype
83+
--- @param bufnr number
84+
--- @param filetype string
85+
--- @param start_line number
86+
--- @param end_line number
87+
--- TODO: fallback to regex highlighting if treesitter fails
8288
function utils.highlight_with_treesitter(bufnr, filetype, start_line, end_line)
8389
local Range = require('vim.treesitter._range')
8490

8591
local root_lang = vim.treesitter.language.get_lang(filetype)
8692
if root_lang == nil then return end
8793

88-
local trees = vim.treesitter.get_parser(bufnr, root_lang)
94+
local success, trees = pcall(vim.treesitter.get_parser, bufnr, root_lang)
95+
if not success then return end
96+
8997
trees:parse({ start_line, end_line })
9098
if not trees then return end
9199

0 commit comments

Comments
 (0)