folke / todo-comments.nvim

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

bug: keyword alt overrides default alts #260

Open andresatierf opened 2 months ago

andresatierf commented 2 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0-dev-2961+g4d52b0cf6

Operating system/version

Linux archlinux 6.8.2-arch2-1

Describe the bug

I'm using LazyVim and I'm trying to add an alt to the FIX keyword

return {
  {
    "folke/todo-comments.nvim",
    opts = {
      keywords = {
        FIX = { alt = { "CHANGE ME" } },
      },
    },
  },
}

this overrides the default alts for FIX resulting in only FIX and CHANGE ME working.

So I tried to append it to the options

return {
  {
    "folke/todo-comments.nvim",
    opts = function(_, opts)
      local alts = { FIX = { "CHANGE ME" } }

      if opts.keywords ~= nil and opts.keywords.FIX ~= nil and opts.keywords.FIX.alt ~= nil then
        vim.list_extend(opts.keywords.FIX.alt, alts.FIX)
      else
        return vim.tbl_deep_extend("force", opts, { keywords = { FIX = { alt = alts.FIX } } })
      end
    end,
  },
}

but this doesn't work because the param opts is always empty, resulting in the same thing

Steps To Reproduce

install todo comments and try to add a single alt

Expected Behavior

I understand why the first method fails, it overrides the list. But I expected the second one to work

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",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
github-actions[bot] commented 4 days 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.