folke / todo-comments.nvim

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

bug: `comments_only` false-negative #290

Closed alexmozaidze closed 2 weeks ago

alexmozaidze commented 2 weeks ago

Did you check docs and existing issues?

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
  3. Indent it >>
    -- TODO: add S-eggs (super eggs) to the game
  4. 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>>"
eXvimmer commented 2 weeks ago

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.

alexmozaidze commented 2 weeks ago

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.

gtabuada commented 2 weeks ago

Having the same issue.

EDIT: maybe related to #180?

folke commented 2 weeks ago

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

folke commented 2 weeks ago

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

folke commented 2 weeks ago

Did some testing and seems fixed

eXvimmer commented 2 weeks ago

@folke it's fixed. Thanks!