Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(comments): option to override comments_only per filetype #277

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Todo comes with the following defaults:
after = "fg", -- "fg" or "bg" or empty
pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlighting (vim regex)
comments_only = true, -- uses treesitter to match keywords in comments only
-- override the comments_only option for specific filetypes
comments_only_ft_override = {
markdown = false, -- override comments_only for markdown files
},
max_line_len = 400, -- ignore lines longer than this
exclude = {}, -- list of file types to exclude highlighting
},
Expand Down
5 changes: 4 additions & 1 deletion lua/todo-comments/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ M.loaded = false
M.ns = vim.api.nvim_create_namespace("todo-comments")

--- @class TodoOptions
-- TODO: add support for markdown todos
local defaults = {
signs = true, -- show icons in the signs column
sign_priority = 8, -- sign priority
Expand Down Expand Up @@ -50,6 +49,10 @@ local defaults = {
pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlightng (vim regex)
-- pattern = { [[.*<(KEYWORDS)\s*:]], [[.*\@(KEYWORDS)\s*]] }, -- pattern used for highlightng (vim regex)
comments_only = true, -- uses treesitter to match keywords in comments only
-- override the comments_only option for specific filetypes
comments_only_ft_override = {
markdown = false, -- override comments_only for markdown files
},
max_line_len = 400, -- ignore lines longer than this
exclude = {}, -- list of file types to exclude highlighting
throttle = 200,
Expand Down
10 changes: 9 additions & 1 deletion lua/todo-comments/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,18 @@ function M.highlight(buf, first, last, _event)
local ok, start, finish, kw = pcall(M.match, line)
local lnum = first + l - 1

local ft_overrides = Config.options.highlight.comments_only_ft_override
local ft = vim.api.nvim_buf_get_option(buf, "filetype")

local comments_only = Config.options.highlight.comments_only
if ft_overrides ~= nil and ft_overrides[ft] ~= nil then
comments_only = ft_overrides[ft]
end

if ok and start then
---@cast kw string
if
Config.options.highlight.comments_only
comments_only
and not M.is_quickfix(buf)
and not M.is_comment(buf, lnum, start - 1)
then
Expand Down
Loading