dmmulroy / tsc.nvim

A Neovim plugin for seamless, asynchronous project-wide TypeScript type-checking using the TypeScript compiler (tsc)
MIT License
403 stars 21 forks source link

Allow for callback on set qflist #42

Closed BenFCSains closed 8 months ago

BenFCSains commented 8 months ago

Hi, Just wondering if supporting something like this would be possible. I am using Trouble for Diagnostics, quickfix etc.

Currently I am using an autocmd to hook into when the quickfix list is opened to swap to using trouble:

vim.api.nvim_create_augroup("trouble-quickfix", { clear = true })
vim.api.nvim_create_autocmd({ "BufWinEnter" }, {
    group = "trouble-quickfix",
    callback = function()
        if vim.bo.buftype == "quickfix" then
            print(#(vim.fn.getqflist()))
            if #(vim.fn.getqflist()) > 0 then
                vim.schedule(function()
                    vim.cmd("Trouble quickfix")
                end)
                vim.schedule(function()
                    vim.cmd("ccl")
                end)
            else
                vim.schedule(function()
                    vim.cmd("TroubleClose")
                end)
            end
        end
    end,
})

However this does mean this behaviour isn't scoped to just tsc errors. Would it be possible to expose an on_qflist_open callback to allow scoping this kind of behaviour?

Happy to make a PR if this would be of interest

Cheers