Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add support for doublewidth Nerd Font icons #282

Open
1 task done
powerman opened this issue Jun 27, 2024 · 15 comments
Open
1 task done

feature: Add support for doublewidth Nerd Font icons #282

powerman opened this issue Jun 27, 2024 · 15 comments
Labels
enhancement New feature or request stale

Comments

@powerman
Copy link

Did you check the docs?

  • I have read all the todo-comments.nvim docs

Is your feature request related to a problem? Please describe.

Please read neovim/neovim#29496 - it describes patch for Neovim which marks Nerd Font icons doublewidth and this result in breaking your plugin (described in details in neovim/neovim#29496 (comment)).

Describe the solution you'd like

Not sure is mentioned in linked comment fix based on 'ambiwidth' vim option will works, but please consider some solution to the issue.

Describe alternatives you've considered

Manual copy&paste of default icons setup into own custom config and removing extra spaces after icons works. But it's not really convenient for new users who don't want to customize used icons.

Additional context

Sorry, I havn't read all the todo-comments.nvim docs - it's not relevant to the issue, but I had to check the box to submit.

@powerman powerman added the enhancement New feature or request label Jun 27, 2024
@folke
Copy link
Owner

folke commented Jul 7, 2024

I don't really understand any of this.
Can you give a repro that breaks todo-comments?

@powerman
Copy link
Author

powerman commented Jul 7, 2024

To make doublewidth Nerd Font icons work in Neovim we should mark their codepoints as doublewidth:

-- Fix icon width for Nerd Fonts v3.2.1.
vim.fn.setcellwidths {
    { 0x23fb, 0x23fe, 2 }, -- IEC Power Symbols
    { 0x2665, 0x2665, 2 }, -- Octicons
    { 0x2b58, 0x2b58, 2 }, -- IEC Power Symbols
    { 0xe000, 0xe00a, 2 }, -- Pomicons
    { 0xe0b8, 0xe0c8, 2 }, -- Powerline Extra
    { 0xe0ca, 0xe0ca, 2 }, -- Powerline Extra
    { 0xe0cc, 0xe0d7, 2 }, -- Powerline Extra
    { 0xe200, 0xe2a9, 2 }, -- Font Awesome Extension
    { 0xe300, 0xe3e3, 2 }, -- Weather Icons
    { 0xe5fa, 0xe6b5, 2 }, -- Seti-UI + Custom
    { 0xe700, 0xe7c5, 2 }, -- Devicons
    { 0xea60, 0xec1e, 2 }, -- Codicons
    { 0xed00, 0xefce, 2 }, -- Font Awesome
    { 0xf000, 0xf2ff, 2 }, -- Font Awesome
    { 0xf300, 0xf375, 2 }, -- Font Logos
    { 0xf400, 0xf533, 2 }, -- Octicons
    { 0xf0001, 0xf1af0, 2 }, -- Material Design
}

With this setup todo-comments (using it default config) show error on loading plugin:

Failed to run `config` for todo-comments.nvim
                                                                                                    
Vim:E239: Invalid sign text:                                                                      
                                                                                                    
# stacktrace:                                                                                       
  - /todo-comments.nvim/lua/todo-comments/config.lua:141 _in_ **signs**                             
  - /todo-comments.nvim/lua/todo-comments/config.lua:134 _in_ **_setup**                            
  - /todo-comments.nvim/lua/todo-comments/config.lua:95 _in_ **setup**                              

This happens because you define keywords elements with extra space after an icon. When icon itself became doublewidth that extra space makes sign value too long (3 columns instead of 2) - which result in above error.

I propose to add a check for actual icon width before defining keywords and add/remove that extra space after an icons depending on check result.

@powerman
Copy link
Author

powerman commented Jul 7, 2024

Here is example implementation:

local function fix_sign_width(keyword)
    local code = vim.fn.char2nr(keyword.icon, true)
    for _, value in ipairs(vim.fn.getcellwidths()) do
        if value[1] <= code and code <= value[2] and value[3] > 1 then
            return
        end
    end
    keyword.icon = keyword.icon .. ' '
end

---@param opts TodoOptions
local function fix_icons(opts)
    for _, keyword in pairs(opts.keywords) do
        fix_sign_width(keyword)
    end
end

--- Example:

-- Fix icon width for Nerd Fonts v3.2.1.
vim.fn.setcellwidths {
    { 0x23fb, 0x23fe, 2 }, -- IEC Power Symbols
    { 0x2665, 0x2665, 2 }, -- Octicons
    { 0x2b58, 0x2b58, 2 }, -- IEC Power Symbols
    { 0xe000, 0xe00a, 2 }, -- Pomicons
    { 0xe0b8, 0xe0c8, 2 }, -- Powerline Extra
    { 0xe0ca, 0xe0ca, 2 }, -- Powerline Extra
    { 0xe0cc, 0xe0d7, 2 }, -- Powerline Extra
    { 0xe200, 0xe2a9, 2 }, -- Font Awesome Extension
    { 0xe300, 0xe3e3, 2 }, -- Weather Icons
    { 0xe5fa, 0xe6b5, 2 }, -- Seti-UI + Custom
    { 0xe700, 0xe7c5, 2 }, -- Devicons
    { 0xea60, 0xec1e, 2 }, -- Codicons
    { 0xed00, 0xefce, 2 }, -- Font Awesome
    { 0xf000, 0xf2ff, 2 }, -- Font Awesome
    { 0xf300, 0xf375, 2 }, -- Font Logos
    { 0xf400, 0xf533, 2 }, -- Octicons
    { 0xf0001, 0xf1af0, 2 }, -- Material Design
}

---@type TodoOptions
local opts = {
    keywords = {
        FIX = { icon = '' },
        TODO = { icon = '' },
        HACK = { icon = '' },
        WARN = { icon = '' },
        PERF = { icon = '' },
        NOTE = { icon = '' },
        TEST = { icon = '󰝖' },
    },
}
fix_icons(opts)
vim.print(opts)

@powerman
Copy link
Author

powerman commented Jul 7, 2024

Can you give a repro that breaks todo-comments?

To repro just add that vim.fn.setcellwidths call before loading todo-comments.

Copy link
Contributor

github-actions bot commented Aug 7, 2024

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.

@github-actions github-actions bot added the stale label Aug 7, 2024
@powerman
Copy link
Author

powerman commented Aug 7, 2024

bump

@github-actions github-actions bot removed the stale label Aug 8, 2024
@dsully
Copy link

dsully commented Aug 27, 2024

Related: neovim/neovim#30014

@xfzv
Copy link

xfzv commented Aug 30, 2024

After updating to neovim/neovim@5f95f12, todo-comments prints the following error when entering a buffer:

Failed to run `config` for todo-comments.nvim

Vim:E239: Invalid sign text: ⚠️ 

# stacktrace:
  - /todo-comments.nvim/lua/todo-comments/config.lua:141 _in_ **signs**
  - /todo-comments.nvim/lua/todo-comments/config.lua:134 _in_ **_setup**
  - /todo-comments.nvim/lua/todo-comments/config.lua:95 _in_ **setup**
  - vim/_editor.lua:0
  - /telescope.nvim/lua/telescope/actions/set.lua:200 _in_ **run_replace_or_original**
  - /telescope.nvim/lua/telescope/actions/mt.lua:65 _in_ **run_replace_or_original**
  - /telescope.nvim/lua/telescope/actions/mt.lua:65 _in_ **run_replace_or_original**
  - /telescope.nvim/lua/telescope/actions/mt.lua:65 _in_ **key_func**
  - /telescope.nvim/lua/telescope/mappings.lua:293

My config:

return {
  "folke/todo-comments.nvim",
  dependencies = { "nvim-lua/plenary.nvim" },
  event = { "BufReadPost", "BufNewFile" },
  opts = {
    highlight = {
      comments_only = false,
    },
    keywords = {
      BUG = { icon = "🐛", color = "error", alt = { "BROKEN", "FIXME", "ISSUE" } },
      HACK = { icon = "🔥", color = "warning" },
      IDEA = { icon = "💡", color = "test" },
      NOTE = { icon = "ℹ️", color = "hint", alt = { "INFO" } },
      TEST = { icon = "🧪", color = "test", alt = { "EXPERIMENT", "TESTING" } },
      TODO = { icon = "", color = "info" },
      WARN = { icon = "⚠️", color = "warning", alt = { "WARNING", "XXX" } },
    },
  },
}

Edit: the error is gone now after updating to newer Neovim commits.

Copy link
Contributor

github-actions bot commented Oct 2, 2024

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.

@github-actions github-actions bot added the stale label Oct 2, 2024
@powerman
Copy link
Author

powerman commented Oct 2, 2024

bump

@github-actions github-actions bot removed the stale label Oct 3, 2024
Copy link
Contributor

github-actions bot commented Nov 3, 2024

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.

@github-actions github-actions bot added the stale label Nov 3, 2024
@powerman
Copy link
Author

powerman commented Nov 3, 2024

bump

@github-actions github-actions bot removed the stale label Nov 4, 2024
Copy link
Contributor

github-actions bot commented Dec 4, 2024

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.

@github-actions github-actions bot added the stale label Dec 4, 2024
@powerman
Copy link
Author

powerman commented Dec 4, 2024

bump

@github-actions github-actions bot removed the stale label Dec 5, 2024
Copy link
Contributor

github-actions bot commented Jan 5, 2025

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.

@github-actions github-actions bot added the stale label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

4 participants