Skip to content

Commit ddb4547

Browse files
Wrap get_parser in pcall to avoid errors
# Details Issue: #101 While we still won't be able to parse the file in these error cases it will at least prevent error messages from being propagated up to the user.
1 parent b75f681 commit ddb4547

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Diff for: lua/render-markdown/ui.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ end
115115
---@param buf integer
116116
---@return render.md.Mark[]
117117
function M.parse_buffer(buf)
118+
local has_parser, parser = pcall(vim.treesitter.get_parser, buf)
119+
if not has_parser then
120+
return {}
121+
end
118122
-- Make sure injections are processed
119-
local parser = vim.treesitter.get_parser(buf)
120123
if not parser:is_valid() then
121124
parser:parse(true)
122125
end

Diff for: tests/data/ft_override.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Mounting sda1
2+
/dev/sda1 /mnt/shared vfat size=200m
3+
4+
# Mounting tmpfs
5+
tmpfs /mnt/tmpfs tmpfs size=100m
6+
7+
# vim: ft=fstab

Diff for: tests/ft_override_spec.lua

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local async_tests = require('plenary.async.tests')
2+
local util = require('tests.util')
3+
4+
async_tests.describe('ft_override.md', function()
5+
async_tests.it('default', function()
6+
util.setup('tests/data/ft_override.md')
7+
8+
local actual = util.get_actual_marks()
9+
util.marks_are_equal({}, actual)
10+
end)
11+
end)

0 commit comments

Comments
 (0)