Skip to content

[FEATURE] Append arbitrary lua code before or after generated plugin setup #1407

@becknik

Description

@becknik

This isn't a bug report, but rather a feature proposal/ discussion

Description

In the generated init.lua file, I'd like to be able add some lua code before/ after (or even inside) of a plugins setup() call to tidy up the generated file's structure.

Adding the code to extraCofnigLua or extraConfigLuaPre just adds tons of code to the top/ bottom of the init.lua and therefore doesn't creates any tight coupling between it and the plugin it's relevant or even necessary for. This goes against what I saw on some neovim setup and also should help human readers to understand the init.lua, which might be shown as a setup-reference to plain old neovim users.

Example

When trying to configure plugins.cmp, I'm in need of the following code snippet:

local symbols = {
  Variable = '𝛸',
  -- --snip--
}

local kinds = vim.lsp.protocol.CompletionItemKind
for i, kind in ipairs(kinds) do
  kinds[i] = symbols[kind] or kind
end

local signs = { Error = "󰅚 ", Warn = "󰀪 ", Hint = "󰌶 ", Info = "" }
for type, icon in pairs(signs) do
  local hl = "DiagnosticSign" .. type
  vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end

I'm currently solving this as follows:

  extraConfigLuaPre = builtins.readFile ./cmp.lua;

  # https://github.com/hrsh7th/nvim-cmp
  plugins.cmp = {
    enable = true;
    autoEnableSources = true;
    settings = {
      # __raw = builtins.readFile ./cmp.lua;
      formatting.format = ''
          function(entry, vim_item)
            vim_item.kind = symbols[vim_item.kind]
            vim_item.menu = '[' .. entry.source.name .. ']'
            return vim_item
          end
      '';
      # --snip--
    };
  };

This results in the symbols map being created beginning from line 36 and cmp from line 243, and my config is rather small atm...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions