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

🐞 Bug: highlight_groups custom groups stopped working #172

Closed
2 tasks done
AndreM222 opened this issue Oct 9, 2024 · 5 comments · Fixed by #253
Closed
2 tasks done

🐞 Bug: highlight_groups custom groups stopped working #172

AndreM222 opened this issue Oct 9, 2024 · 5 comments · Fixed by #253
Assignees
Labels
bug Something isn't working

Comments

@AndreM222
Copy link

Before reporting:

  • Ensure that the issue is reproducable on the main branch.
  • Ensure that there isn't an issue on this(either open or closed).

Problem:

very recently the highlight_groups section, or more specifically the groups I added to it has stopped working.
I know before it worked just fine but I don't know which update might have broken that.

As you can see in the corner of the headers. it should have highlight same to the background
スクリーンショット 2024-10-08 23 25 31

Steps to reproduce the issue:

 {
        "OXY2DEV/markview.nvim",
        lazy = true,      -- Recommended
        ft = "markdown", -- If you decide to lazy-load anyway
        config = function ()

            local colors = require("markview.colors");

            require("markview").setup({
                modes = { "n", "i", "no", "c" },
                hybrid_modes = { "i", "n" },

                -- This is nice to have
                callbacks = {
                    on_enable = function (_, win)
                        vim.wo[win].conceallevel = 2;
                        vim.wo[win].concealcursor = "nc";
                    end
                },
                checkboxes = {
                    enable = true,

                    checked = {
                        text = "󰡖", hl = "MarkviewCheckboxChecked"
                    },
                    unchecked = {
                        text = "", hl = "MarkviewCheckboxUnchecked"
                    }
                },
                links = {
                    enable = true,

                    images = {
                        icon = "",
                        hl = "MarkviewImageLink",
                    }
                },
                highlight_groups = {
                    {
                        group_name = "MarkviewHeading1Corner",
                        value = function ()
                            return { fg = colors.get_hl_value(0, "MarkviewHeading1", "bg") };
                        end
                    },
                    {
                        group_name = "MarkviewHeading2Corner",
                        value = function ()
                            return { fg = colors.get_hl_value(0, "MarkviewHeading2", "bg") };
                        end
                    },
                    {
                        group_name = "MarkviewHeading3Corner",
                        value = function ()
                            return { fg = colors.get_hl_value(0, "MarkviewHeading3", "bg") };
                        end
                    },
                    {
                        group_name = "MarkviewHeading4Corner",
                        value = function ()
                            return { fg = colors.get_hl_value(0, "MarkviewHeading4", "bg") };
                        end
                    },
                    {
                        group_name = "MarkviewHeading5Corner",
                        value = function ()
                            return { fg = colors.get_hl_value(0, "MarkviewHeading5", "bg") };
                        end
                    },
                    {
                        group_name = "MarkviewHeading6Corner",
                        value = function ()
                            return { fg = colors.get_hl_value(0, "MarkviewHeading6", "bg") };
                        end
                    },
                },
                headings = {
                    enable = true,
                    shift_width = 0,

                    heading_1 = {
                        style = "label",

                        padding_left = " ",
                        padding_right = " ",

                        corner_left = "",
                        corner_left_hl = "MarkviewHeading1Corner",
                        corner_right = "",
                        corner_right_hl = "MarkviewHeading1Corner",

                        hl = "MarkviewHeading1"
                    },
                    heading_2 = {
                        style = "label",

                        padding_left = " ",
                        padding_right = " ",

                        corner_left = "",
                        corner_left_hl = "MarkviewHeading2Corner",
                        corner_right = "",
                        corner_right_hl = "MarkviewHeading2Corner",

                        hl = "MarkviewHeading2"
                    },
                    heading_3 = {
                        style = "label",

                        padding_left = " ",
                        padding_right = " ",

                        corner_left = "",
                        corner_left_hl = "MarkviewHeading3Corner",
                        corner_right = "",
                        corner_right_hl = "MarkviewHeading3Corner",

                        hl = "MarkviewHeading3"
                    },
                    heading_4 = {
                        style = "label",

                        padding_left = " ",
                        padding_right = " ",

                        corner_left = "",
                        corner_left_hl = "MarkviewHeading4Corner",
                        corner_right = "",
                        corner_right_hl = "MarkviewHeading4Corner",

                        hl = "MarkviewHeading4"
                    },
                    heading_5 = {
                        style = "label",

                        padding_left = " ",
                        padding_right = " ",

                        corner_left = "",
                        corner_left_hl = "MarkviewHeading5Corner",
                        corner_right = "",
                        corner_right_hl = "MarkviewHeading5Corner",

                        hl = "MarkviewHeading5"
                    },
                    heading_6 = {
                        style = "label",

                        padding_left = " ",
                        padding_right = " ",

                        corner_left = "",
                        corner_left_hl = "MarkviewHeading6Corner",
                        corner_right = "",
                        corner_right_hl = "MarkviewHeading6Corner",

                        hl = "MarkviewHeading6"
                    },
                }
            })
        end
    },

Expected behavior:

The corner of the headers should match the headers background

Neovim version:

NVIM v0.10.2 Build type: Release LuaJIT 2.1.1727870382

@AndreM222 AndreM222 added the bug Something isn't working label Oct 9, 2024
@OXY2DEV
Copy link
Owner

OXY2DEV commented Oct 9, 2024

This is due to changes to how highlights are applied.

markview.colors was deprecated due to lack of interest & maintainability reasons. It will be removed later.

This is the new syntax.

highlight_groups = {
  {
    output = function (hl)
      return {
        group_name = "Heading1Corner",
        value = {
           fg = hl.hex(hl.color("bg", { "MarkviewHeading1" }, nil, nil))
        }
      }
    end
  }
}

Here's the function definitions.

---@param opt string Option to get, e.g. bg, fg
---@param colors string[] List of highlight groups to check into. Useful for groups that get inherited from multiple highlight groups.
---@param light any Value to return if the opt wasn't found and the background is "light".
---@param dark any Value to return if the opt wasn't found and the background is "dark".
---
---@return integer[] The R, G, B value
hl.color(opt, colors, light, dark)

---@param color integer[] The R, G, B values
---@return string The hexadecimal value of the color.
hl.hex(color)

markview.colors was replaced with markview.highlights to make maintaining it easier. markview.colors will be removed in a future update.

Manually setting highlight groups is no longer recommended as it may overwrite the highlight groups provided by the colorscheme(assuming it supports this plugin). So, it will not be documented in the wiki.

@AndreM222
Copy link
Author

AndreM222 commented Jan 25, 2025

This is due to changes to how highlights are applied.

markview.colors was deprecated due to lack of interest & maintainability reasons. It will be removed later.

This is the new syntax.

highlight_groups = {
{
output = function (hl)
return {
group_name = "Heading1Corner",
value = {
fg = hl.hex(hl.color("bg", { "MarkviewHeading1" }, nil, nil))
}
}
end
}
}
Here's the function definitions.

---@param opt string Option to get, e.g. bg, fg
---@param colors string[] List of highlight groups to check into. Useful for groups that get inherited from multiple highlight groups.
---@param light any Value to return if the opt wasn't found and the background is "light".
---@param dark any Value to return if the opt wasn't found and the background is "dark".

---@return integer[] The R, G, B value
hl.color(opt, colors, light, dark)

---@param color integer[] The R, G, B values
---@return string The hexadecimal value of the color.
hl.hex(color)
markview.colors was replaced with markview.highlights to make maintaining it easier. markview.colors will be removed in a future update.

Manually setting highlight groups is no longer recommended as it may overwrite the highlight groups provided by the colorscheme(assuming it supports this plugin). So, it will not be documented in the wiki.

So the new update makes this broken. I am unable to figure out what to do since it wasnt documented.

                highlight_groups = {

                    {
                        output = function (hl)
                            return {
                                group_name = "MarkviewHeading1Corner",
                                value = { fg = hl.hex(hl.color("bg", {  "MarkviewHeading1" }, nil, nil)) }
                            }
                        end
                    },
                    {
                        output = function (hl)
                            return {
                                group_name = "MarkviewHeading2Corner",
                                value = { fg = hl.hex(hl.color("bg", {  "MarkviewHeading2" }, nil, nil)) }
                            }
                        end
                    },
                    {
                        output = function (hl)
                            return {
                                group_name = "MarkviewHeading3Corner",
                                value = { fg = hl.hex(hl.color("bg", {  "MarkviewHeading3" }, nil, nil)) }
                            }
                        end
                    },
                    {
                        output = function (hl)
                            return {
                                group_name = "MarkviewHeading4Corner",
                                value = { fg = hl.hex(hl.color("bg", {  "MarkviewHeading4" }, nil, nil)) }
                            }
                        end
                    },
                    {
                        output = function (hl)
                            return {
                                group_name = "MarkviewHeading5Corner",
                                value = { fg = hl.hex(hl.color("bg", {  "MarkviewHeading5" }, nil, nil)) }
                            }
                        end
                    },
                    {
                        output = function (hl)
                            return {
                                group_name = "MarkviewHeading6Corner",
                                value = { fg = hl.hex(hl.color("bg", {  "MarkviewHeading6" }, nil, nil)) }
                            }
                        end
                    }
                },

Error Message

Failed to run 'config for markview.nvim
attempt to compare string with number
# stacktrace:
- /markview.nvim/lua/markview/highlights.lua:495 _in_
- /markview.nvim/lua/markview/highlights. lua:1679 _in_
**create**
**Setup**
- /markview.nvim/lua/markview.lua:1296 _in_ **setup**
- Lua/andrem222/plugins/markdown.lua:13 _in_ **config**
- /opt/homebrew/Cellar/neovim/0.10.3/share/nvim/runtime/filetype.lua:36
- /opt/homebrew/Cellar/neovim/0.10.3/share/nvim/runtime/filetype.lua:35

@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 26, 2025

Structure for highlight_groups has been changed from config.hl[] to { [string]: config.hl }.

You also no longer receive function (hl) as the highlight module can now be loaded with local hl = require("markview.highlights");

So you will need something like this,

highlight_groups = {
  -- The property name is ZZ because we want to load this last.
  ["ZZ"] = function ()
    local hl = require("markview.highlights");

    local _o = {};

    for h = 1, 6, 1 do
      -- `hl.color()` → `hl.get_property()` as it can now get highlight group properties too
      local bg = hl.get_property("bg", { "MarkviewHeading" .. h }, nil, nil);

      if bg then
        table.insert(_o, {
          group_name = "MarkviewHeading" .. h .. "Corner",
          -- `hl.hex()` → `hl.rgb_to_hex()` as the previous name wasn't obvious(because there's now HSL & Lab color functions too).
          value = { fg = hl.rgb_to_hex(bg) }
        });
      end
    end

    return _o;
  end
}

@AndreM222
Copy link
Author

Thank you brother. keep doing amazing. Thanks for the plugin. It has been great using it.

@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 26, 2025

Glad you stuck around!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants