Skip to content

Commit a5c255c

Browse files
committed
fix: properly escape commentstring #19
1 parent 03fc95a commit a5c255c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lua/todo-comments/highlight.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ function M.highlight(buf, first, last)
4242
local pattern
4343
if Config.options.highlight.comments_only and not M.is_quickfix(buf) then
4444
local comment_str = vim.bo.commentstring:gsub("%s+", "")
45-
comment_str = vim.fn.escape(comment_str, "*+?")
45+
comment_str = vim.fn.escape(comment_str, "*+?{}()[]<>.-$^")
4646
pattern = comment_str:gsub("%%s", [[\s*]] .. Config.hl_regex .. ".*")
4747
pattern = vim.fn.escape(pattern, "%")
4848
end
4949

5050
for l, line in ipairs(lines) do
51-
local start, finish, kw = M.match(line, pattern)
51+
local ok, start, finish, kw = pcall(M.match, line, pattern)
52+
-- HACK: redo without the comment pattern for now if we get an error
53+
if not ok then
54+
start, finish, kw = M.match(line)
55+
end
5256
local lnum = first + l - 1
5357

5458
if kw then

0 commit comments

Comments
 (0)