MattiasMTS / cmp-dbee

Autocompletion for nvim-dbee
MIT License
49 stars 9 forks source link

Add class function to check availability #26

Closed phdah closed 2 months ago

phdah commented 2 months ago

This is an implementation to solve https://github.com/MattiasMTS/cmp-dbee/issues/22

The issue is that the is_available is evaluated at startup, when the plugin is loaded. At this time, dbee is not loaded and it is always set to false.

We can use the added function independently as well as inside of the constructor of the source itself. This way, we will actually try to load the source with the setup() function after we have opened the Dbee client.

Not sure if this is the intention, but for the completion to work, one has to run the setup after Dbee is open. Hence, I have this auto command to trigger completion for SQL files

local auGroup = vim.api.nvim_create_augroup("nvim-dbee-custom", {clear = true})
vim.api.nvim_create_autocmd("FileType", {
    group = auGroup,
    pattern = "sql",
    callback = function()
        require('cmp').setup.filetype({"sql", "mysql", "plsql"}, {
            sources = require('cmp').config.sources{
                { name = 'cmp-dbee' }
            }
        })
        require("cmp-dbee").setup({})
    end
})

Since this already checks if dbee is loaded, it won't effect performance of any random sql files being opened.

Let me know what you think @MattiasMTS

phdah commented 2 months ago

Looking over this PR, https://github.com/MattiasMTS/cmp-dbee/pull/25, this might already have solved the issue, but slightly different. Will look into if this is the case.

EDIT: This is the case, and the above auto command is not needed with that solution. Will close this PR.