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

feat(plugin): support running all init functions #1801

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MeanderingProgrammer
Copy link
Contributor

Description

I have taken to structuring my configuration per language similar to LazyVim's extras. Sometimes for a particular plugin I want to specify initialization logic within the spec for the language. I use the init function for this but currently only the last one of these is ran.

For example I'll have a top level conform.nvim config:

return {
    'stevearc/conform.nvim',
    opts = {
        formatters_by_ft = {},
        format_after_save = function()
            return { lsp_format = 'fallback' }
        end,
    },
}

Then for each language I'll update the options using opts and do some environment setup related to the formatter in the init function. For example my typescript extra looks like:

return {
    {
        'stevearc/conform.nvim',
        init = function()
            -- Avoid running when project does not use prettier
            vim.env.PRETTIERD_LOCAL_PRETTIER_ONLY = 1

            -- Due to prettierd not picking up changes
            -- https://github.com/fsouza/prettierd/issues/719
            vim.api.nvim_create_autocmd('BufWritePost', {
                group = vim.api.nvim_create_augroup('RestartPrettierd', { clear = true }),
                pattern = '*prettier*',
                callback = function()
                    vim.fn.system('prettierd restart')
                end,
            })
        end,
        opts = {
            formatters_by_ft = {
                javascript = { 'prettierd' },
                typescript = { 'prettierd' },
            },
        },
    },
}

The issue comes up if I want to have initialization logic related to a formatter for another language. I can create a toy example if you would like.

This is a niche issue so if you prefer to leave it out totally understandable. There are also workarounds like putting this logic in the opts function, I just prefer having the environment stuff and the options to be separate but its a very minor gripe.

Related Issue(s)

I was unable to find any similar requests.

Screenshots

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant