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] Alpha.nvim's broken after refactor #944

Closed
redyf opened this issue Jan 16, 2024 · 4 comments
Closed

[Bug] Alpha.nvim's broken after refactor #944

redyf opened this issue Jan 16, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@redyf
Copy link
Contributor

redyf commented Jan 16, 2024

Plugin affected: Alpha.nvim
Nixpkgs channel: Unstable
Home-manager version: Master

Description

Alpha.nvim breaks when using type = "group" option for plugins.alpha.layout

When using that option I get the following error:

Erro detectado ao processar VimEnter Autocommands for "*":
Error executing lua callback: ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:365: attempt to call a nil value
stack traceback:
        ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:365: in function <...dir/pack/myNeovimPackages/start/alpha-nvim/lua/
alpha.lua:344>
        ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:389: in function 'layout'
        ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:630: in function 'draw'
        ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:724: in function 'start'
        ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:787: in function <...dir/pack/myNeovimPackages/start/alpha-nvim/lua/
alpha.lua:785>
Aperte ENTER ou digite um comando para continuar

Config

{
  plugins.alpha = {
    enable = true;
    layout = [
      {
        type = "padding";
        val = 4;
      }
      {
        opts = {
          hl = "AlphaHeader";
          position = "center";
        };
        type = "text";
        val = [
          "    ██▀███  ▓█████ ▓█████▄▓██   ██▓  █████▒ "
          "   ▓██ ▒ ██▒▓█   ▀ ▒██▀ ██▌▒██  ██▒▓██   ▒  "
          "   ▓██ ░▄█ ▒▒███   ░██   █▌ ▒██ ██░▒████ ░  "
          "   ▒██▀▀█▄  ▒▓█  ▄ ░▓█▄   ▌ ░ ▐██▓░░▓█▒  ░  "
          "   ░██▓ ▒██▒░▒████▒░▒████▓  ░ ██▒▓░░▒█░     "
          "   ░ ▒▓ ░▒▓░░░ ▒░ ░ ▒▒▓  ▒   ██▒▒▒  ▒ ░     "
          "     ░▒ ░ ▒░ ░ ░  ░ ░ ▒  ▒ ▓██ ░▒░  ░       "
          "     ░░   ░    ░    ░ ░  ░ ▒ ▒ ░░   ░ ░     "
          "      ░        ░  ░   ░    ░ ░              "
          "                                            "
          "              git@github.com:redyf          "
        ];
      }
      {
        type = "padding";
        val = 2;
      }
      {
        opts = {
          hl = "AlphaButtons";
          position = "center";
          spacing = 1;
        };
        type = "group";
        val = [
          {
            command = "<CMD>Telescope find_files<CR>";
            desc = "  Find file";
            shortcut = "f";
          }

          {
            command = ":ene <BAR> startinsert <CR>";
            desc = "  New file";
            shortcut = "n";
          }

          {
            command = ":Telescope oldfiles <CR>";
            desc = "  Recent files";
            shortcut = "r";
          }

          {
            command = ":Telescope live_grep <CR>";
            desc = "  Find text";
            shortcut = "g";
          }

          {
            command = ":lua require('persistence').load()<cr>";
            desc = "  Restore Session";
            shortcut = "s";
          }

          {
            command = ":qa<CR>";
            desc = "  Quit Neovim";
            shortcut = "q";
          }
        ];
      }
    ];
  };
}
@redyf redyf added the bug Something isn't working label Jan 16, 2024
@GaetanLepage
Copy link
Member

Indeed, we have refactored this plugin and got rid of some opinionated code that we were shipping by default.
The current implementation is exactly what the plugin exposes as config options.
I am sorry for the implied changes that you will have to do to keep the same functionality.

To achieve the same config, you have to change the button definitions from

{
  command = "<COMMAND>";
  desc = "<DESC>";
  shortcut = "<SC>";
}

to

{
  type = "button";
  val = "<DESC>";

  on_press.raw = "function() vim.api.nvim_feedkeys("<SC>", "t", false) end";
  # OR
  on_press.raw = "funcion() vim.cmd[[<COMMAND>]] end";

  opts = {
    keymap = ["n" "<SC>" "<COMMAND>" {noremap = true; silent = true; nowait = true;}];
    shortcut = "<SC>";

    # Feel free to customize (or omit) those
    position = "center";
    cursor = 3;
    width = 50;
    align_shortcut = "right";
    hl_shortcut = "Keyword";
  };
}

For example,

{
  command = ":Telescope live_grep <CR>";
  desc = "  Find text";
  shortcut = "g";
}

would give

{
  type = "button";
  val = "  Find text";
  on_press.raw = "require('telescope.builtin').live_grep";

  opts = {
    keymap = ["n" "g" ":Telescope live_grep <CR>" {noremap = true; silent = true; nowait = true;}];
    shortcut = "g";

    # Feel free to customize (or omit) those
    position = "center";
    cursor = 3;
    width = 50;
    align_shortcut = "right";
    hl_shortcut = "Keyword";
  };
}

This is indeed more verbose, but the nixvim philosophy is to respect the options from the plugins and sometimes provide optional helpers.
I will thus close this issue as I am not planning to alter the plugin implementation on our side.
If you have an idea for re-implementing this button opinionated behavior and making it optional in nixvim, please go for it and submit a PR.

@GaetanLepage
Copy link
Member

PS: You can also factorize this in nix using an approach similar as in https://github.com/hbjydev/hvim/blob/3bc249f9a4489ba7150ced08c1d448dbbf5a737a/config/ui/dashboard/default.nix.

@siph
Copy link
Contributor

siph commented Jan 17, 2024

The test configuration seems the throw the same error. Using the latest revision (8104e24):

plugins.alpha = {
      enable = true;

      iconsEnabled = true;
      layout = [
        {
          type = "padding";
          val = 2;
        }
        {
          type = "text";
          val = [
            "███╗   ██╗██╗██╗  ██╗██╗   ██╗██╗███╗   ███╗"
            "████╗  ██║██║╚██╗██╔╝██║   ██║██║████╗ ████║"
            "██╔██╗ ██║██║ ╚███╔╝ ██║   ██║██║██╔████╔██║"
            "██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║"
            "██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║"
            "╚═╝  ╚═══╝╚═╝╚═╝  ╚═╝  ╚═══╝  ╚═╝╚═╝     ╚═╝"
          ];
          opts = {
            position = "center";
            hl = "Type";
          };
        }
        {
          type = "padding";
          val = 2;
        }
        {
          type = "group";
          val = [
            {
              val = "  New file";
              on_press.__raw = "function() vim.cmd[[ene]] end";
            }
            {
              val = " Quit Neovim";
              on_press.__raw = "function() vim.cmd[[qa]] end";
            }
          ];
        }
        {
          type = "padding";
          val = 2;
        }
        {
          type = "text";
          val = "Inspiring quote here.";
          opts = {
            position = "center";
            hl = "Keyword";
          };
        }
      ];
      opts = {
        margin = 0;
        noautocmd = true;

        keymap = {
          press = "<CR>";
          press_queue = "<M-CR>";
        };
      };
    };
Error detected while processing VimEnter Autocommands for "*":
Error executing lua callback: ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:365: attempt to call a nil value
stack traceback:
        ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:365: in function <...dir/pack/myNeovimPackages/start/alpha-nvim/lua/
alpha.lua:344>
        ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:389: in function 'layout'
        ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:630: in function 'draw'
        ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:724: in function 'start'
        ...dir/pack/myNeovimPackages/start/alpha-nvim/lua/alpha.lua:787: in function <...dir/pack/myNeovimPackages/start/alpha-nvim/lua/
alpha.lua:785>
Press ENTER or type command to continue

@GaetanLepage
Copy link
Member

GaetanLepage commented Jan 17, 2024

Indeed, this is a "bug" from alpha itself.
They say that all the keys in opt should be optional.
But actually, you do need to set opts.shortcut for buttons.

Thanks for pointing it out :)
I opened a PR to fix the example: #947

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
Development

No branches or pull requests

3 participants