Skip to content

Commit bc08c11

Browse files
committed
feat(highlight): allow extended highlighting patterns (#185)
Highlights the first capture group (as before), if there is a second (typically nested) capture group, use it for keyword matching. Allows highlighting `TODO(foo)` using `.*<((KEYWORDS)%(\(.{-1,}\))?):`.
1 parent 70a93ce commit bc08c11

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lua/todo-comments/highlight.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ function M.match(str, patterns)
4646
for _, pattern in pairs(patterns) do
4747
local m = vim.fn.matchlist(str, [[\v\C]] .. pattern)
4848
if #m > 1 and m[2] then
49-
local kw = m[2]
50-
local start = str:find(kw)
51-
return start, start + #kw, kw
49+
local match = m[2]
50+
local kw = m[3] ~= "" and m[3] or m[2]
51+
local start = str:find(match, 1, true)
52+
return start, start + #match, kw
5253
end
5354
end
5455
end

0 commit comments

Comments
 (0)