folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.32k stars 344 forks source link

bug: Creating autocmd based on LazyNvim's User Events generates `unexpected event` error #1048

Closed c3n21 closed 1 year ago

c3n21 commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0-dev-c88bb65

Operating system/version

5.15.90.1-microsoft-standard-WSL2

Describe the bug

Creating autocmd based on LazyNvim's User Events generates unexpected event error.

I already tried with standard events like BufReadPre and it works.

Steps To Reproduce

nvim -u repro.lua

Expected Behavior

There shouldn't be any error

Repro

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        'git',
        'clone',
        '--filter=blob:none',
        '--single-branch',
        'https://github.com/folke/lazy.nvim.git',
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

require('lazy').setup({}, {
    root = vim.fn.stdpath('data') .. '/lazy', -- directory where plugins will be installed
    defaults = {
        lazy = false, -- should plugins be lazy-loaded?
        version = nil,
        -- version = "*", -- enable this to try installing the latest stable versions of plugins
    },
    lockfile = vim.fn.stdpath('config') .. '/lazy-lock.json', -- lockfile generated after running update.
    concurrency = nil, ---@type number limit the maximum amount of concurrent tasks
    git = {
        -- defaults for the `Lazy log` command
        -- log = { "-10" }, -- show the last 10 commits
        log = { '--since=3 days ago' }, -- show commits from the last 3 days
        timeout = 120, -- kill processes that take more than 2 minutes
        url_format = 'https://github.com/%s.git',
    },
    dev = {
        -- directory where you store your local plugin projects
        path = '~/projects',
        ---@type string[] plugins that match these patterns will use your local versions instead of being fetched from GitHub
        patterns = {}, -- For example {"folke"}
    },
    install = {
        -- install missing plugins on startup. This doesn't increase startup time.
        missing = false,
        -- try to load one of these colorschemes when starting an installation during startup
        colorscheme = { 'kanagawa' },
    },
    ui = {
        -- a number <1 is a percentage., >1 is a fixed size
        size = { width = 0.8, height = 0.8 },
        -- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
        border = 'none',
        icons = {
            cmd = ' ',
            config = '',
            event = '',
            ft = ' ',
            init = ' ',
            keys = ' ',
            plugin = ' ',
            runtime = ' ',
            source = ' ',
            start = '',
            task = '✔ ',
        },
        throttle = 20, -- how frequently should the ui process render events
    },
    checker = {
        -- automatically check for plugin updates
        enabled = false,
        concurrency = nil, ---@type number? set to 1 to check for updates very slowly
        notify = true, -- get a notification when new updates are found
        frequency = 3600, -- check for updates every hour
    },
    change_detection = {
        -- automatically check for config file changes and reload the ui
        enabled = true,
        notify = true, -- get a notification when changes are found
    },
    performance = {
        cache = {
            enabled = true,
            path = vim.fn.stdpath('state') .. '/lazy/cache',
            -- Once one of the following events triggers, caching will be disabled.
            -- To cache all modules, set this to `{}`, but that is not recommended.
            -- The default is to disable on:
            --  * VimEnter: not useful to cache anything else beyond startup
            --  * BufReadPre: this will be triggered early when opening a file from the command line directly
            disable_events = { 'VimEnter', 'BufReadPre' },
        },
        reset_packpath = true, -- reset the package path to improve startup time
        rtp = {
            reset = true, -- reset the runtime path to $VIMRUNTIME and your config directory
            ---@type string[]
            paths = {}, -- add any custom paths here that you want to indluce in the rtp
            ---@type string[] list any plugins you want to disable here
            disabled_plugins = {
                'gzip',
                'matchit',
                'matchparen',
                'tarPlugin',
                'tohtml',
                'tutor',
                'zipPlugin',
            },
        },
    },
    -- lazy can generate helptags from the headings in markdown readme files,
    -- so :help works even for plugins that don't have vim docs.
    -- when the readme opens with :help it will be correctly displayed as markdown
    readme = {
        root = vim.fn.stdpath('state') .. '/lazy/readme',
        files = { 'README.md' },
        -- only generate markdown helptags for plugins that dont have docs
        skip_if_doc_exists = true,
    },
})

vim.api.nvim_create_autocmd({ 'LazyInstall', 'LazyUpdate' }, {
    group = vim.api.nvim_create_augroup('BumpNeoVim', {
        clear = true,
    }),
    callback = function(args)
        print('hi')
        local version = vim.version()
        local build = version.build
        local config = vim.fn.stdpath('config')
        local version_file = config .. '/version'
        vim.fn.writefile({ build }, version_file, 's')
    end,
})
abeldekat commented 1 year ago

Hello @c3n21,

This discussion could provide useful information.

The type of the event should be User.

Best regards!

c3n21 commented 1 year ago

Hello @c3n21,

This discussion could provide useful information.

The type of the event should be User.

Best regards!

I missed that discussion. Thanks!

abeldekat commented 1 year ago

You're welcome!