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

Add callback to qflist opened #43

Closed benfc1993 closed 8 months ago

benfc1993 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

dmmulroy commented 8 months ago

I'd definitely be open to a PR adding this - do you think there might be a better way to integrate with trouble though? I've had several asks now for that.

benfc1993 commented 8 months ago

Happy to have a look into it, although I don't know if you'd want to make trouble a dependancy. I guess it could be an optional dep, with an option to use it for qf. Kind of how you allow for notify?

dmmulroy commented 8 months ago

That could be an option - I don't know enough about Trouble yet to have a well thought opinion on it yet.

benfc1993 commented 8 months ago

Code is ready to go all working really well, I can't push as I don't have permissions would you be able to grant me perms please.

dmmulroy commented 8 months ago

Awesome, thank you for your time and effort! Could you please create a fork and open a PR that way 🙏

benfc1993 commented 8 months ago

PR raised 😃 #44

dmmulroy commented 8 months ago

Cloed by #44