folke / snacks.nvim

🍿 A collection of small QoL plugins for Neovim
Apache License 2.0
942 stars 15 forks source link

bug: dashboard not launching on the start #97

Open KapJ1coH opened 2 hours ago

KapJ1coH commented 2 hours ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

Windows 10

Describe the bug

Dashboard, when enabled as in the example config does not show up on startup. It is only possible to access it with :lua Snacks.dashboard() and it shows up in a floating window.

Steps To Reproduce

nvim

Expected Behavior

Dashboard needs to show up upon entry into nvim.

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
    spec = {
        {
            "folke/snacks.nvim",
            priority = 1000,
            lazy = false,
            ---@type snacks.Config
            opts = {
                bigfile = { enabled = true },
                dashboard = { enabled = true },
                notifier = {
                    enabled = true,
                    timeout = 3000,
                },
                quickfile = { enabled = true },
                statuscolumn = { enabled = true },
                words = { enabled = true },
                styles = {
                    notification = {
                        wo = { wrap = true } -- Wrap notifications
                    }
                }
            },
            keys = {
                { "<leader>un", function() Snacks.notifier.hide() end,           desc = "Dismiss All Notifications" },
                { "<leader>bd", function() Snacks.bufdelete() end,               desc = "Delete Buffer" },
                { "<leader>gg", function() Snacks.lazygit() end,                 desc = "Lazygit" },
                { "<leader>gb", function() Snacks.git.blame_line() end,          desc = "Git Blame Line" },
                { "<leader>gB", function() Snacks.gitbrowse() end,               desc = "Git Browse" },
                { "<leader>gf", function() Snacks.lazygit.log_file() end,        desc = "Lazygit Current File History" },
                { "<leader>gl", function() Snacks.lazygit.log() end,             desc = "Lazygit Log (cwd)" },
                { "<leader>cR", function() Snacks.rename.rename_file() end,      desc = "Rename File" },
                { "<c-/>",      function() Snacks.terminal() end,                desc = "Toggle Terminal" },
                { "<c-_>",      function() Snacks.terminal() end,                desc = "which_key_ignore" },
                { "]]",         function() Snacks.words.jump(vim.v.count1) end,  desc = "Next Reference",              mode = { "n", "t" } },
                { "[[",         function() Snacks.words.jump(-vim.v.count1) end, desc = "Prev Reference",              mode = { "n", "t" } },
                {
                    "<leader>N",
                    desc = "Neovim News",
                    function()
                        Snacks.win({
                            file = vim.api.nvim_get_runtime_file("doc/news.txt", false)[1],
                            width = 0.6,
                            height = 0.6,
                            wo = {
                                spell = false,
                                wrap = false,
                                signcolumn = "yes",
                                statuscolumn = " ",
                                conceallevel = 3,
                            },
                        })
                    end,
                }
            },
            init = function()
                vim.api.nvim_create_autocmd("User", {
                    pattern = "VeryLazy",
                    callback = function()
                        -- Setup some globals for debugging (lazy-loaded)
                        _G.dd = function(...)
                            Snacks.debug.inspect(...)
                        end
                        _G.bt = function()
                            Snacks.debug.backtrace()
                        end
                        vim.print = _G.dd -- Override print to use snacks for `:=` command

                        -- Create some toggle mappings
                        Snacks.toggle.option("spell", { name = "Spelling" }):map("<leader>us")
                        Snacks.toggle.option("wrap", { name = "Wrap" }):map("<leader>uw")
                        Snacks.toggle.option("relativenumber", { name = "Relative Number" }):map("<leader>uL")
                        Snacks.toggle.diagnostics():map("<leader>ud")
                        Snacks.toggle.line_number():map("<leader>ul")
                        Snacks.toggle.option("conceallevel",
                            { off = 0, on = vim.o.conceallevel > 0 and vim.o.conceallevel or 2 }):map(
                            "<leader>uc")
                        Snacks.toggle.treesitter():map("<leader>uT")
                        Snacks.toggle.option("background",
                            { off = "light", on = "dark", name = "Dark Background" }):map("<leader>ub")
                        Snacks.toggle.inlay_hints():map("<leader>uh")
                    end,
                })
            end,
        }
        -- add any other plugins here
    },
})
KapJ1coH commented 2 hours ago

As an example, here's my repro with my config for alpha.nvim in which the dashboard shows up.

-- Alpha (dashboard) for neovim

local options

-- Only runs this script if Alpha Screen loads -- only if there isn't files to read
if (vim.api.nvim_exec('echo argc()', true) == "0")
then
    --math.randomseed( os.time() ) -- For random header.

    -- Create button for initial keybind.
    --- @param sc string
    --- @param txt string
    --- @param hl string
    --- @param keybind string optional
    --- @param keybind_opts table optional
    local function button(sc, txt, hl, keybind, keybind_opts)
        local sc_ = sc:gsub("%s", ""):gsub("SPC", "<leader>")

        local opts = {
            position       = "center",
            shortcut       = sc,
            cursor         = 5,
            width          = 50,
            align_shortcut = "right",
            hl_shortcut    = hl,
        }

        if keybind then
            keybind_opts = vim.F.if_nil(keybind_opts, { noremap = true, silent = true, nowait = true })
            opts.keymap = { "n", sc_, keybind, keybind_opts }
        end

        local function on_press()
            local key = vim.api.nvim_replace_termcodes(sc_ .. '<Ignore>', true, false, true)
            vim.api.nvim_feedkeys(key, "normal", false)
        end

        return {
            type     = "button",
            val      = txt,
            on_press = on_press,
            opts     = opts,
        }
    end

    -- All custom headers
    Headers = {

        {
            [[            .-'''''-.    ]],
            [[          .'         `.  ]],
            [[         :             : ]],
            [[        :               :]],
            [[        :      _/|      :]],
            [[         :   =/_/      : ]],
            [[          `._/ |     .'  ]],
            [[       (   /  ,|...-'    ]],
            [[        \_/^\/||__       ]],
            [[     _/~  `""~`"` \_     ]],
            [[  __/  -'.  ` .  `\_\__  ]],
            [[/jgs     \           \-.\ ]],
        }, -- jgs

        {
            [[=================     ===============     ===============   ========  ========]],
            [[\\ . . . . . . .\\   //. . . . . . .\\   //. . . . . . .\\  \\. . .\\// . . //]],
            [[||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\/ . . .||]],
            [[|| . .||   ||. . || || . .||   ||. . || || . .||   ||. . || ||. . . . . . . ||]],
            [[||. . ||   || . .|| ||. . ||   || . .|| ||. . ||   || . .|| || . | . . . . .||]],
            [[|| . .||   ||. _-|| ||-_ .||   ||. . || || . .||   ||. _-|| ||-_.|\ . . . . ||]],
            [[||. . ||   ||-'  || ||  `-||   || . .|| ||. . ||   ||-'  || ||  `|\_ . .|. .||]],
            [[|| . _||   ||    || ||    ||   ||_ . || || . _||   ||    || ||   |\ `-_/| . ||]],
            [[||_-' ||  .|/    || ||    \|.  || `-_|| ||_-' ||  .|/    || ||   | \  / |-_.||]],
            [[||    ||_-'      || ||      `-_||    || ||    ||_-'      || ||   | \  / |  `||]],
            [[||    `'         || ||         `'    || ||    `'         || ||   | \  / |   ||]],
            [[||            .===' `===.         .==='.`===.         .===' /==. |  \/  |   ||]],
            [[||         .=='   \_|-_ `===. .==='   _|_   `===. .===' _-|/   `==  \/  |   ||]],
            [[||      .=='    _-'    `-_  `='    _-'   `-_    `='  _-'   `-_  /|  \/  |   ||]],
            [[||   .=='    _-'          '-__\._-'         '-_./__-'         `' |. /|  |   ||]],
            [[||.=='    _-'                                                     `' |  /==.||]],
            [[=='    _-'                        N E O V I M                         \/   `==]],
            [[\   _-'                                                                `-_   /]],
            [[ `''                                                                      ``' ]],
        },

    }

    --
    -- Sections for Alpha.
    --

    local header = {
        type = "text",
        val = Headers[math.random(#Headers)],
        -- val = Headers[1],
        opts = {
            position = "center",
            hl       = "Whitespace"
            -- wrap = "overflow";
        }
    }

    local footer = {
        type = "text",
        -- Change 'rdn' to any program that gives you a random quote.
        -- https://github.com/BeyondMagic/scripts/blob/master/quotes/rdn
        -- Which returns one to three lines, being each divided by a line break.
        -- Or just an array: { "I see you:", "Above you." }
        val  = {
            "We accept the love we think we deserve.",
            "                           Mr. Callahan",
            "The Perks of Being a Wallflower",
        },
        hl   = "NvimTreeRootFolder",
        opts = {
            position = "center",
            hl       = "Whitespace",
        }
    }

    local buttons = {
        type = "group",
        val = {
            button("e", "  New Buffer", 'RainbowRed', ':tabnew<CR>'),
            button("f", "  Find file", 'RainbowYellow', ':Telescope find_files<CR>'),
            button("h", "  Recently opened files", 'RainbowBlue', ':Telescope oldfiles<CR>'),
            button("l", "  Projects", 'RainbowOrange', ':Telescope marks<CR>'),
            button("r", "  Frecency/MRU", 'RainbowCyan', ':Telescope oldfiles<CR>'),
            button("g", "  Open Last Session", 'RainbowGreen', ':source ~/.config/nvim/session.vim<CR>'),
            button("m", "  Word Finder", 'RainbowViolet', ':Telescope live_grep<CR>'),
        },
        opts = {
            spacing = 1,
        }
    }

    --
    -- Centering handler of ALPHA
    --

    local ol = {                                -- occupied lines
        icon            = #header.val,          -- CONST: number of lines that your header will occupy
        message         = #footer.val,          -- CONST: because of padding at the bottom
        length_buttons  = #buttons.val * 2 - 1, -- CONST: it calculate the number that buttons will occupy
        neovim_lines    = 2,                    -- CONST: 2 of command line, 1 of the top bar
        padding_between = 3,                    -- STATIC: can be set to anything, padding between keybinds and header
    }

    local left_terminal_value = vim.api.nvim_get_option('lines') -
        (ol.length_buttons + ol.message + ol.padding_between + ol.icon + ol.neovim_lines)

    -- Not screen enough to run the command.
    if (left_terminal_value >= 0) then
        local top_padding    = math.floor(left_terminal_value / 2)
        local bottom_padding = left_terminal_value - top_padding

        --
        -- Set alpha sections
        --

        options              = {
            layout = {
                { type = "padding", val = top_padding },
                header,
                { type = "padding", val = ol.padding_between },
                buttons,
                footer,
                { type = "padding", val = bottom_padding },
            },
            opts = {
                margin = 5
            },
        }
    end

    --else
    --vim.api.nvim_exec('silent source ~/.config/nvim/session.vim', false)
end

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
    spec = {
        {
            "goolord/alpha-nvim",
            dependencies = { 'nvim-tree/nvim-web-devicons', },
            lazy = false,
            -- enabled = false,
            config = function()
                if (options ~= nil) then
                    require 'alpha'.setup(options)
                end
            end
        },
    },
})
folke commented 2 hours ago

Your snacks repro is all wrong. So that code could never work. Did you actually test it?

dseravalli commented 2 hours ago

I've just updated my plugin and added dashboard to snacks config, and my isn't launching automatically either. It looks great when I launch it manually though so thank you for this addition :)

https://github.com/dseravalli/nvim.config/blob/main/lua/dseravalli/lazy/snacks.lua#L7

macos, latest versions of nvim, lazy, and snacks

KapJ1coH commented 2 hours ago

I just updated it, it was a mistype. I tested both repros and the snack one shows this image The snacks plugin still works, for example the terminal pop-up is showing up.

Let me know if my config is still wrong, it is very much a possibility

folke commented 1 hour ago

Can you update snacks, run :checkhealth snacks and report back with the output? Just added a bunch of health checks to narrow down the issue

dseravalli commented 1 hour ago
==============================================================================
snacks: require("snacks.health").check()

Snacks ~
- OK setup called

Snacks.bigfile ~
- OK setup {enabled}

Snacks.dashboard ~
- OK setup {enabled}
- OK setup ran
- WARNING dashboard did not open: `stdin is a pipe`

Snacks.lazygit ~
- OK {lazygit} installed

Snacks.notifier ~
- OK setup {enabled}
- OK is ready

Snacks.quickfile ~
- OK setup {enabled}

Snacks.statuscolumn ~
- OK setup {enabled}

Snacks.terminal ~
- OK shell configured
  - `vim.o.shell`: /bin/zsh
  - `parsed`: { "/bin/zsh" }

Snacks.toggle ~
- OK {which-key} is installed

Snacks.words ~
- OK setup {enabled}
MediocreMitch commented 1 hour ago

I am having the same issue. Here is my checkhealth output.


==============================================================================
snacks: require("snacks.health").check()

Snacks ~
- OK setup called

Snacks.bigfile ~
- WARNING setup {disabled}

Snacks.dashboard ~
- OK setup {enabled}

Snacks.lazygit ~
- ERROR {lazygit} not installed

Snacks.notifier ~
- WARNING setup {disabled}
- ERROR is not ready

Snacks.quickfile ~
- WARNING setup {disabled}

Snacks.statuscolumn ~
- WARNING setup {disabled}

Snacks.terminal ~
- OK shell configured
  - `vim.o.shell`: cmd.exe
  - `parsed`: { "cmd.exe" }

Snacks.toggle ~
- WARNING {which-key} is not installed

Snacks.words ~
- WARNING setup {disabled}
ChrisGVE commented 49 minutes ago

Same issue here. My snacks.nvim config is here and, I used the latest :checkhealth snacks below:

==============================================================================
snacks: require("snacks.health").check()

Snacks ~
- OK setup called

Snacks.bigfile ~
- OK setup {enabled}

Snacks.dashboard ~
- OK setup {enabled}
- OK setup ran
- WARNING dashboard did not open: `stdin is a pipe`

Snacks.lazygit ~
- OK {lazygit} installed

Snacks.notifier ~
- OK setup {enabled}
- OK is ready

Snacks.quickfile ~
- OK setup {enabled}

Snacks.statuscolumn ~
- OK setup {enabled}

Snacks.terminal ~
- OK shell configured
  - `vim.o.shell`: /bin/zsh
  - `parsed`: { "/bin/zsh" }

Snacks.toggle ~
- OK {which-key} is installed

Snacks.words ~
- OK setup {enabled}
KapJ1coH commented 34 minutes ago

Here's a better repro that's works properly, maybe that will help. It is the same result as my full repo. The :lua Snacks.dashboard() still works in this one.

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
    spec = {
        {
            "folke/snacks.nvim",
            priority = 1000,
            lazy = false,
            opts = {
                dashboard = { enabled = true },
            }
        },
        -- add any other plugins here
    },
})

It gives me this for the healthcheck:

snacks: require("snacks.health").check()

Snacks ~
- OK setup called

Snacks.bigfile ~
- WARNING setup {disabled}

Snacks.dashboard ~
- OK setup {enabled}
- OK setup ran
- WARNING dashboard did not open: `stdin is a pipe`

Snacks.lazygit ~
- OK {lazygit} installed

Snacks.notifier ~
- WARNING setup {disabled}
- ERROR is not ready

Snacks.quickfile ~
- WARNING setup {disabled}

Snacks.statuscolumn ~
- WARNING setup {disabled}

Snacks.terminal ~
- OK shell configured
  - `vim.o.shell`: cmd.exe
  - `parsed`: { "cmd.exe" }

Snacks.toggle ~
- WARNING {which-key} is not installed

Snacks.words ~
- WARNING setup {disabled}
dpetka2001 commented 19 minutes ago

@ChrisGVE I just tried your dotfiles and it works perfectly fine on my laptop. I believe it might be something related to your OS, terminal or shell. I use Linux Mint, kitty and fish shell.

folke commented 16 minutes ago

Ok, I thought I was being smart with checking for pipes, but it seems this doesn't work always for some reason....

What is your Neovim version?

dseravalli commented 14 minutes ago

Mine is:

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1727870382
rachartier commented 9 minutes ago

Yep. With my dotfiles inside a Docker container (Ubuntu 24.04, same as my WSL2 distro), it works.

My dotfiles inside this Docker are a true copy of what I use outside Docker, and it works great here. You can try it here:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/rachartier/dotfiles/main/.config/scripts/setup-container-env.sh)"

Version:

NVIM v0.11.0-dev-1172+gf164e1e35c
Build type: RelWithDebInfo
LuaJIT 2.1.1731601260

Ubuntu 24.04
Wezterm
tmux 3.5a
zsh 5.9 (x86_64-ubuntu-linux-gnu)

EDIT: no bob-nvim for me

folke commented 9 minutes ago

Are you using bob-nvim by any chance?

dseravalli commented 7 minutes ago

Are you using bob-nvim by any chance?

no, homebrew installed nvim

rachartier commented 6 minutes ago

Ah! Maybe it comes from nvim executed with the appimage? It seems like with nvim installed from apt, it works.