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: fire autocmd on test result #487

Closed
disrupted opened this issue Feb 23, 2025 · 1 comment
Closed

feat: fire autocmd on test result #487

disrupted opened this issue Feb 23, 2025 · 1 comment

Comments

@disrupted
Copy link

disrupted commented Feb 23, 2025

I use a statusline component for Neotest to show the number of running and completed tests. I noticed that the counts sometimes don't update until I move my cursor. I think it would be better if I could subscribe to Neotest events. I think the easiest way would be if Neotest fired a custom User autocmd each time a test result comes in. This would also allow for other automations.

@disrupted
Copy link
Author

figured out how to exec custom User autocmds using listeners

opts

consumers = {
    autocmd_run = function(client)
        client.listeners.run = function()
            vim.schedule(function()
                vim.api.nvim_exec_autocmds('User', {
                    pattern = 'NeotestRun',
                    modeline = false,
                })
            end)
        end
        return {}
    end,
    autocmd_results = function(client)
        client.listeners.results = function(
            adapter_id,
            results,
            partial
        )
            vim.schedule(function()
                vim.api.nvim_exec_autocmds('User', {
                    pattern = 'NeotestResult',
                    modeline = false,
                    data = {
                        adapter_id = adapter_id,
                        results = results,
                        partial = partial,
                    },
                })
            end)
        end
        return {}
    end,
}

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

No branches or pull requests

1 participant