goolord / alpha-nvim

a lua powered greeter like vim-startify / dashboard-nvim
MIT License
1.73k stars 101 forks source link

Seemingly random error when setting text highlight groups and centring content vertically #265

Closed Shock9616 closed 4 months ago

Shock9616 commented 4 months ago

I'm really not sure what to make of this error. It seems to randomly happen ~50% of the time with no changes to my config whatsoever. This is the config I've got currently

local alpha = require("alpha")
local headers = require("user.config.plugins.alpha.headers").portal
local quotes = require("user.config.plugins.alpha.quotes").portal

local function centerVert(header)
    return (vim.fn.winheight(0) / 2) - ((#header + 3) / 2)
end

local header = headers[math.random(#headers)]

alpha.setup({
    layout = {
    { type = "padding", val = centerVert(header) },
    {
        type = "text",
        val = header,
        opts = {
        position = "center",
        hl = "Comment",
        },
    },
    { type = "padding", val = 2 },
    {
        type = "text",
        val = quotes[math.random(#quotes)],
        opts = {
        position = "center",
        hl = "Number",
        },
    },
    },
})

vim.cmd("autocmd FileType alpha setlocal nofoldenable")

headers and quotes are just tables with portal-themed ascii art and quotes to be randomly selected from.

Screenshot 2024-02-19 at 3 44 18 PM

^ The error traceback

Screenshot 2024-02-19 at 3 47 06 PM

^ The dashboard after the error

Screenshot 2024-02-19 at 4 05 22 PM

^ The dashboard as it should be (the only difference is that I closed and re-opened neovim)

The issue seems to be with some combination of centerVert() and setting the highlights for the header and the quote. It works perfectly if I have one or the other, but having both results in the ~50% chance of erroring.

I am using a nightly build of neovim (v0.10.0-dev-2354+g4860cc5bd) and Neovide, but I have also tested with the v0.9.5 release in the terminal and it still happens.

Shock9616 commented 4 months ago

After a lot more searching I have fixed this issue by replacing my centerVert() function with headerPadding from this comment