folke / todo-comments.nvim

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

bug: Next/Previous Todo Comment jumps outside of comments #301

Open geoffreylefebvre opened 1 month ago

geoffreylefebvre commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

MacOS 12.7.5

Describe the bug

When navigating a file containing KEYWORDS outside of comments, next/prev todo comments jumps to these even if the buffer has treesitter support and todo-comments is configured with comments_only. This issue happens with Go code which contains context.TODO(), and todo-comments using a pattern that does not require a colon.

I think the problem is that is_comment() in highlight.lua returns true or nil, and the caller in jump.lua explicitly checks for false. A solution would be for is_comment to return false when the buffer has treesitter support and the match is outside of a comment, or for the caller to test against ~= true instead of == false.

Steps To Reproduce

  1. Configure todo-comments with a pattern that does not require a colon and comments_only set to true.
  2. Edit Go source file with calls to context.TODO().
  3. Navigate through todo comments using next/prev todo comments (i.e ]-t. [-t using LazyVim default bindings).

Expected Behavior

next/prev todo comments should not jump to context.TODO() (or any of the KEYWORDS) outside comments.

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    { "folke/todo-comments.nvim", 
      opts = { 
        highlight = { 
          pattern = [[.*<(KEYWORDS)>]],
          comments_only = true },
        },
      },
    },
    -- add any other plugins here
  },
})
github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

geoffreylefebvre commented 3 weeks ago

bump