folke / todo-comments.nvim

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

Keyword isn't highlighted #181

Closed hinell closed 1 year ago

hinell commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.9.0-dev-d3355ad

Operating system/version

Linux Ubuntu 22.04.1 LTS

Describe the bug

The keyword specified by the config doesn't work.

Steps To Reproduce

See config below

Expected Behavior

Working keywords

Repro

require("todo-comments").setup({
    keywords = {
        CONTINUE = { icon = "", color = "info" }
    },
    merge_keywords = true
})
afulki commented 1 year ago

I have the same issue, one thing I noticed is if you add the keyword to the ALT, it works correctly:

  {
    "folke/todo-comments.nvim",
    opts = function(_, opts)
      opts.merge_keywords = true
      opts.keywords = {
        URL = { icon = " ", color = "hint", alt = { "Url", "url" } },
      }
    end,
  },

This won't highlight URL, but will highlight Url and url, it is however showing up correctly in Telescope.

hinell commented 1 year ago

@afulki Doesn't work for me sadly!

hinell commented 1 year ago

Any progress on this?

MikeDupree commented 1 year ago

Same issue, not getting any highlighting.

Thanatermesis commented 1 year ago

I was able to configure it with this loader, in nvchad (lazy):

  -- make visible the TODO / FIXME / etc keywrods with extra features - https://github.com/folke/todo-comments.nvim
  {
    "folke/todo-comments.nvim",
    lazy = false, -- this is required otherwise the colors sometimes bugs (async loading?)
    requires = "nvim-lua/plenary.nvim",
    init = function()
      require("core.utils").lazy_load "todo-comments.nvim"
    end,
    opts = function()
      return require "plugins.configs.todocomments"  -- use return required
    end,
    config = function(_, opts)
      require("todo-comments").setup(opts)
    end,
  },

Then in the directory plugins/configs/todocomments.lua (or you can change it), a file containing a full copy-paste from the defaults settings in the source code where you modify it yourself, like:

-- local theme16 = require("base46").get_theme_tb "base_16"
local theme30 = require("base46").get_theme_tb "base_30"

local options = {

  keywords = {
    FIX = {
      icon = " ", -- icon used for the sign, and in search results
      color = "error", -- can be a hex color, or a named color (see below)
      alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, -- a set of other keywords that all map to this FIX keywords
      -- signs = false, -- configure signs for some keywords individually
    },
  -- TODO = { icon = " ", color = "info" },
    -- TODO = { icon = "󰢌 ", color = "todos" },
    TODO = { icon = "󰮱 ", color = "todo" },
    HACK = { icon = " ", color = "warning" },
    WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX", "FAILED" } },
--    PERF = { icon = " ", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } },
    PERF = { icon = " ", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } },
--    NOTE = { icon = " ", color = "hint", alt = { "INFO" } },
    NOTE = { icon = " ", color = "hint", alt = { "INFO" } },
    TEST = { icon = "⏲ ", color = "test", alt = { "TESTING", "PASSED", "SUCCESS", "CORRECT" } },
  },
  gui_style = {
    fg = "NONE", -- The gui style to use for the fg highlight group.
    bg = "BOLD", -- The gui style to use for the bg highlight group.
  },
  merge_keywords = true, -- when true, custom keywords will be merged with the defaults
  -- highlighting of the line containing the todo comment
  -- * before: highlights before the keyword (typically comment characters)
  -- * keyword: highlights of the keyword
  -- * after: highlights after the keyword (todo text)
  highlight = {
    multiline = false, -- enable multine todo comments
    multiline_pattern = "^.", -- lua pattern to match the next multiline from the start of the matched keyword
    multiline_context = 10, -- extra lines that will be re-evaluated when changing a line
    before = "", -- "fg" or "bg" or empty
    keyword = "wide", -- "fg", "bg", "wide", "wide_bg", "wide_fg" or empty. (wide and wide_bg is the same as bg, but will also highlight surrounding characters, wide_fg acts accordingly but with fg)
    after = "fg", -- "fg" or "bg" or empty
    -- pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlighting (vim regex)
    pattern = [[.*<(KEYWORDS)(:|;|\s+|\.|,|;|$)]], -- same but don't strictly require the : after the keyword
    comments_only = true, -- uses treesitter to match keywords in comments only
    max_line_len = 400, -- ignore lines longer than this
    exclude = {
        "TelescopePrompt",
        "TelescopeResults",
        "help",
        "lazy",
        "lspinfo",
        "mason",
        "nvcheatsheet",
        "nvdash",
        "terminal",
        'nerdtree',
        'unite',
        'OverseerForm',
        'OverseerList',
    }, -- list of file types to exclude highlighting TODO fill
    throttle = 200,
  },
  -- list of named colors where we try to extract the guifg from the
  -- list of highlight groups or use the hex color if hl not found as a fallback
  colors = {
    -- error = { "DiagnosticError", "ErrorMsg", "#DC2626" },
    error = { theme30.red },
    -- warning = { "DiagnosticWarn", "WarningMsg", "#FBBF24" },
    warning = { theme30.orange },
    -- info = { "DiagnosticInfo", "#2563EB" },
    -- info = { theme30.blue },
    -- hint = { "DiagnosticHint", "#10B981" },
    hint = { theme30.grey_fg2 },
    -- default = { "Identifier", "#7C3AED" },
    -- test = { "Identifier", "#FF00FF" },
    test = { theme30.green },
    -- todo = { "#ff00ff" }
    todo = { theme30.purple }
  },
  search = {
    command = "rg",
    args = {
      "--color=never",
      "--no-heading",
      "--with-filename",
      "--line-number",
      "--column",
    },
    -- regex that will be used to match keywords.
    -- don't replace the (KEYWORDS) placeholder
    -- pattern = [[\b(KEYWORDS):]], -- ripgrep regex
    pattern = [[\b(KEYWORDS)\b]], -- match without the extra colon. You'll likely get false positives
  },

}

return options

Check also the issues with the default config mentioned here: https://github.com/folke/todo-comments.nvim/issues/57#issuecomment-1532101532

hinell commented 1 year ago

@Thanatermesis So did it work? @MikeDupree Thumb it up in first place!

Thanatermesis commented 1 year ago

@hinell yes for me it works now, I suggest to use the entire config I pasted and then modify it as you need

lfilho commented 1 year ago

For anyone landing on this thread, if you're not getting the highlight, make sure you're typing TODO: and not TODO -- the default config requires the :! Main readme teaches how to change that.

Here's my Lazy config for that:

{
      "folke/todo-comments.nvim",
      event = "VeryLazy",
      opts = {
        highlight = {
          pattern = [[.*<(KEYWORDS)\s*]],
        },
        search = {
          pattern = [[\b(KEYWORDS)\b]],
        },
      },
}
hinell commented 1 year ago

image

As of 8febc60a76feefd8203077ef78b6a262ea1a41f9 version it started to highlight custom tags. Didn't test it extensively though. Close it for now.

Feel free to request REOPENING.