rebelot/heirline.nvim

Neovim Nightly Deprecating API

Closed this issue · 7 comments

neovim/neovim#22693

With this PR, nvim_get_hl_by_name is deprecated for the new nvim_get_hl API. This will need to be handled in Heirline.

https://github.com/rebelot/heirline.nvim/blob/master/lua/heirline/utils.lua#L2

Do you think it's best to check for nvim version or just go with it?

bew commented

Check nvim version? Or presence of the function?
Otherwise it's a big breaking change for people not on nightly

Yeah definitely. Presence of the function is a good approach. If you want an example, AstroNvim has a similar function that has been updated to take this new API into consideration:

https://github.com/AstroNvim/AstroNvim/blob/nightly/lua/astronvim/utils/init.lua#L58-L75

It's also important to note that they respond with slightly different outputs. The old API returns with foreground and background while the new API responds with fg and bg. This is also shown in the AstroNvim example.

local nvim_get_hl = vim.fn.exists("*nvim_get_hl") == 1
    and function(name)
        return vim.api.nvim_get_hl(0, { name = name, link = false })
    end
    or function(name)
        return vim.api.nvim_get_hl_by_name(name, vim.o.termguicolors)
    end

---Get highlight properties for a given highlight name
---@param name string
---@return table
function M.get_highlight(name)
    local hl = nvim_get_hl(name)
    if vim.o.termguicolors then
        hl.fg = hl.foreground
        hl.bg = hl.background
        hl.sp = hl.special
        hl.foreground = nil
        hl.background = nil
        hl.special = nil
    else
        hl.ctermfg = hl.foreground
        hl.ctermbg = hl.background
        hl.foreground = nil
        hl.background = nil
        hl.special = nil
    end
    return hl
end

In the future, utils.get_highlight might be deprecated altogether of be just a tiny wrapper around nvim_get_hl

This block technically won't work because hl.foreground and hl.background will not exist in the new API.

yup, just found out, will take the verbose way...