File tree 1 file changed +9
-1
lines changed
1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -79,13 +79,21 @@ function utils.combine_markdown_lines(lines)
79
79
return combined_lines
80
80
end
81
81
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
82
88
function utils .highlight_with_treesitter (bufnr , filetype , start_line , end_line )
83
89
local Range = require (' vim.treesitter._range' )
84
90
85
91
local root_lang = vim .treesitter .language .get_lang (filetype )
86
92
if root_lang == nil then return end
87
93
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
+
89
97
trees :parse ({ start_line , end_line })
90
98
if not trees then return end
91
99
You can’t perform that action at this time.
0 commit comments