james1236 / backseat.nvim

A neovim plugin that uses GPT to highlight and explain code readability issues
178 stars 8 forks source link

Use diagnostics API to inline descriptions #15

Open williamboman opened 1 year ago

williamboman commented 1 year ago

Hello! I think it'd be nice if the diagnostics API (:h diagnostic-api) was used to inject the feedback into the buffer. Currently it seems to be using a bespoke implementation via virtual lines. By leveraging the diagnostics API instead, users get a standardized interface for controlling behaviour. Personally, this would allow me to use the keybindings I'm familiar with to jump to next/previous diagnostic, moving diagnostics to quickfix, disabling a specific diagnostic source, etc.

I have a fairly simple plugin that uses this approach that may be used as reference, I'd also be happy to contribute with a PR myself.

-- Show diagnostics in virtual lines
vim.diagnostic.config {
    backseat = {
        virtual_lines = true,
        virtual_text = false,
        sign = false,
    }
}

-- Show diagnostics in virtual text
vim.diagnostic.config {
    backseat = {
        virtual_lines = false,
        virtual_text = true,
        sign = true,
    }
}

-- Only show signs where descriptions exists (users can then expand the diagnostic via `vim.diagnostic.open_float()` for example)
vim.diagnostic.config {
    backseat = {
        virtual_lines = false,
        virtual_text = false,
        sign = true,
    }
}

-- Disable backseat diagnostics entirely
vim.diagnostic.config {
    backseat = false,
}
james1236 commented 1 year ago

Hi, thanks for the suggestion! I think this is a better first step than #2 for now.

I have tried to add this in the diagnostics branch fc44f8ea1ab0f880d382490e0141a667daa0bde8

Currently, I am using

backseat = {
    virtual_lines = false,
    virtual_text = false,
    sign = false,
}

to give invisible diagnostics since I can't find a way to get multiple virtual lines or user specified hl groups working with diagnostics. This still lets you use vim.diagnostic.goto_next() and such to move around and use :BackseatClear to remove them from the buffer.

There are some issues, I think I will need to store all the diagnostics/extmarks in a table indexed by buffer number to fix them

Any help would be appreciated!