folke/todo-comments.nvim

bug: `comments_only` false-negative

Closed this issue · 7 comments

Did you check docs and existing issues?

  • I have read all the todo-comments.nvim docs
  • I have searched the existing issues of todo-comments.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.9.5

Operating system/version

Android 13 (Termux)

Describe the bug

Whenever the comment is indented, it is not recognized by is_comment function whenever comments_only = true.

This was tested on the master branch of the plugin.

Steps To Reproduce

  1. Run nvim a.lua
  2. Input a todo comment
-- TODO: add S-eggs (super eggs) to the game
  1. Indent it >>
  -- TODO: add S-eggs (super eggs) to the game
  1. Observe it as it fades sadly

Expected Behavior

It recognizes a comment by taking a line/range and checking for any comment captures, instead of doing so on a single character.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  { "folke/todo-comments.nvim", opts = {} },
  -- add any other plugins here

  {
    "nvim-treesitter/nvim-treesitter",
    config = function()
      require "nvim-treesitter".setup()
      require "nvim-treesitter.configs".setup {
        highlight = {
          enable = true,
        },
        ensure_installed = {
          "lua"
        },
      }
    end
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

vim.cmd "edit a.lua"
vim.cmd.norm "I-- TODO: add S-eggs (super eggs) to the game"
vim.cmd.norm "yyp>>"

I have the same issue.

// NOTE: only the first indentation is highlighted.
  // NOTE: this is not

I'm using v0.10 and these are my opts

opts = {
	signs = true,
	highlight = {
		multiline = false,
		multiline_context = 0,
		keyword = "fg",
		before = "",
		after = "",
	},
},

Please note, I'm only highlighting the fg.

This is because it checks 1 character to determine a comment when, ideally, it would check a range in the buffer for comment capture. I reckon it can be fixed using vim.treesitter.query.get and Query:iter_captures.

Having the same issue.

EDIT: maybe related to #180?

Most likely yes. That's why I hate merging other people's PR's for things that I don't need.
If anyone wants to provide a PR to fix it, be my guest.

If not, I'll just revert #180 and #288 tomorrow

I reverted those two PRs and merged #255 instead.
Not sure if that one shows the same problem, so let me know

Did some testing and seems fixed

@folke it's fixed. Thanks!