folke / todo-comments.nvim

✅ Highlight, list and search todo comments in your projects
Apache License 2.0
3.09k stars 88 forks source link

bug: regex capturing groups not working as they were in version 1.2.0 #302

Open fvall opened 1 month ago

fvall commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.9.5

Operating system/version

Linux/PopOs

Describe the bug

Using the recommended options in the README file, I have amended the regex patters to suit my workflow. They were working just fine when I tested it with version 1.2.0. I have recently updated to v.1.3.0 and the highlight behaviour has changed, even though the regex patterns did not.

After playing a bit with the configuration, it seems to me the regex capturing groups are not working as they were previously. In my custom regex, I add a modifier to the capturing group, and I think that is causing the issue.

Steps To Reproduce

Switch between versions 1.2.0 and the latest one (as of writing it is 1.3.0) and check the Todo comments in the script below.

With version 1.2.0

With version 1.3.0

Expected Behavior

I am not sure whether this is now the expected behaviour after version 1.3.0 or if it is indeed a bug. I read the release notes and I saw some comments about changing some of the regex logic. I also tried to change my regex to see if would resolve the issue, but it did not work either.

Repro

local plug = {
  {
    "folke/todo-comments.nvim",
    name = "todo_comments",
    lazy = false,
    tag = "v1.2.0",  -- fixing version, remove here to cause the issue
    dependencies = {
      "nvim-lua/plenary.nvim",
    },
    opts = {
      highlight = {
        before = "",
        keyword = "bg",
        after = "fg",

        -- ===================================
        --   This is my custom regex pattern
        -- ===================================
        pattern = [[.*<(KEYWORDS)\s?(\(\a*\))?\s*:]], -- pattern or table of patterns, used for highlighting (vim regex)

      },
      search = {
        command = "rg",
        args = {
          "--color=never",
          "--no-heading",
          "--with-filename",
          "--line-number",
          "--column",
        },

        -- ===================================
        --   This is my custom regex pattern
        -- ===================================
        pattern = [[\b(KEYWORDS)\s?(\(\w*\))?\s*:]], -- ripgrep regex

      },
}

  },
}

-- TODO(fvall): this a named todo
-- TODO: This is a normal todo
vim.keymap.set("n", "<leader>fd", "<cmd>TodoTelescope<cr>", {desc = "Find todo"})
return plug
wuxiao889 commented 1 month ago

meet this too pattern = [[\b(KEYWORDS)\(\w+\)?:]] cant work

kamskry commented 2 weeks ago

I think this is due to the changes in this PR https://github.com/folke/todo-comments.nvim/pull/255

I updated my patterns to:

      highlight = {
        -- vimgrep regex, supporting the pattern TODO(name):
        pattern = [[.*<((KEYWORDS)%(\(.{-1,}\))?):]],
      },
      search = {
        -- ripgrep regex, supporting the pattern TODO(name):
        pattern = [[\b(KEYWORDS)(\(\w*\))*:]],
      },

And it's working again!