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] Not possible to define custom extension for lualine #2130

Closed
1 task done
Wraul opened this issue Aug 31, 2024 · 4 comments · Fixed by #2135
Closed
1 task done

[BUG] Not possible to define custom extension for lualine #2130

Wraul opened this issue Aug 31, 2024 · 4 comments · Fixed by #2135
Labels
bug Something isn't working

Comments

@Wraul
Copy link

Wraul commented Aug 31, 2024

Field Description
Plugin lualine
Nixpkgs unstable
Home Manager unstable
  • I have read the FAQ and my bug is not listed there.

Description

While migrating my configuration to NixVim I discovered a limitation that prevents me from completely achieving my desired configuration.

The upstream lualine plugin allows the user to define custom extensions by providing a object in the list of extensions. See lualine documentation for details.

Unless I'm missing something this isn't currently possible.

Minimal, Reproducible Example (MRE)

programs.nixvim = {
    plugins.lualine = {
      enable = true;
      extensions = [
        {
          sections = {
            lualine_a = [ "filename" ];
          };
          inactive_sections = {
            lualine_x = [ "location" ];
          };
          filetypes = [ "markdown" ];
        }
      ];
    };
}
@Wraul Wraul added the bug Something isn't working label Aug 31, 2024
@khaneliman
Copy link
Contributor

I'm in the middle of migrating our lualine module to our new standards that will support this better in #2080.

@Wraul
Copy link
Author

Wraul commented Sep 1, 2024

Thank you for expediting fixing this. It is very much appreciated ❤️.

Unfortunately the fix isn't 100% complete. This oversight could very much be due to my lackluster example though.
The regular sections has special handling for mapping "name" to the first element in the lua record. This is something that should happen in the extension sections as well.

So a more complete example would be like this

programs.nixvim = {
    plugins.lualine = {
      enable = true;
      extensions = [
        {
          sections = {
            lualine_a = [ {
              name = "branch";
              icon = "<U+F418>";
            }];
            lualine_y = [ "progress" ];
            lualine_z = [ "location" ];
          };
          inactive_sections = {
            lualine_x = [ "location" ];
          };
          filetypes = [ "fugitive" ];
        }
      ];
    };
}

And the extensions section should translate to the following lua

{
  extensions = {
    {
      filetypes = { "fugitive" },
      inactive_sections = { lualine_x = { "location" } },
      sections = {
        lualine_a = { { "branch", icon = "<U+F418>" } },
        lualine_y = { "progress" },
        lualine_z = { "location" },
    },
  },
},

But at the moment it appears to be translated to the following

{
  extensions = {
    {
      filetypes = { "fugitive" },
      inactive_sections = { lualine_x = { "location" } },
      sections = {
        lualine_a = { { icon = "<U+F418>", name = "branch" } },
        lualine_y = { "progress" },
        lualine_z = { "location" },
    },
  },
},

@MattSturgeon
Copy link
Member

MattSturgeon commented Sep 1, 2024

The regular sections has special handling for mapping "name" to the first element in the lua record. This is something that should happen in the extension sections as well.

This is likely something we would remove when refactoring the plugin, as we try to avoid having any unpredictable transformations applied to freeform options.

Instead, you would have to use our "unkeyed" attrs hack:

This nix attrset:

{
  __unkeyed-1 = "a";
  __unkeyed-2 = "b";
  c = "c";
  d = "d";
}

Produces this lua table:

{
  "a",
  "b",
  c = "c",
  d = "d"
}

@Wraul
Copy link
Author

Wraul commented Sep 1, 2024

@MattSturgeon I see, makes sense I guess.

Thank you so much for the hint! With that I was able to produce my desired configuration.

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

Successfully merging a pull request may close this issue.

3 participants