MattiasMTS / cmp-dbee

Autocompletion for nvim-dbee

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Load after nvim-dbee is lazy loaded on keymap

petobens opened this issue · comments

Hi! If try to load cmp-dbee after nvim-dbee using lazy like:

    {
        'kndndrj/nvim-dbee',
        branch = 'spring_cleaning',
        dependencies = {
            'MunifTanjim/nui.nvim',
            -- FIXME: Can't lazy load this
            {
                'MattiasMTS/cmp-dbee',
                ft = { 'sql' },
                lazy = true,
            },
        },
        build = function()
            require('dbee').install()
        end,
        keys = '<Leader>db',
        config = function()
            require('plugin-config.dbee_config')
        end,
    },

I get an error saying:

Failed to source `/home/pedro/.local/share/nvim/lazy/cmp-dbee/after/plugin/cmp-dbee.lua`

vim/_editor.lua:0: nvim_exec2()../home/pedro/.local/share/nvim/lazy/cmp-dbee/after/plugin/cmp-dbee.lua: Vim(source):E5113: Error while calling lua chunk: .../.local/share/nvim/lazy/nvim-dbee/lua/dbee/api/state.lua
:28: setup() has not been called yet

If I change the lazy flag to false then cmp-dbee loads but I get the following error:

.../.local/share/nvim/lazy/cmp-dbee/lua/cmp-dbee/source.lua:147: attempt to call field 'is_core_loaded' (a nil value)

Any pointers? Thanks!

Hi @petobens ! Thanks for the issue. Yeah this is very much a WIP plugin.
I'll try to make some time to give this a bit more love. In the meantime, you can lazy load it on filetype (presumably).

If you have any other feedback currently - please reach out and make more issues! :D

For starters, this is my configuration for cmp-dbee and nvim-dbee:
https://github.com/MattiasMTS/.dotfiles/blob/main/.config/nvim/lua/plugins/coding.lua#L39-L43
in conjunction with
https://github.com/MattiasMTS/.dotfiles/blob/main/.config/nvim/lua/plugins/dbee.lua#L6-L64

I'll check why you receive this error. My hunch would be that the nvim-dbee binary wasn't (or something similar) at this level https://github.com/MattiasMTS/cmp-dbee/blob/main/lua/cmp-dbee/source.lua#L146-L151. That could be moved to the top level configuration tho. Again, I'll check! 😄

Great thanks for the quick feedback!

Hi @MattiasMTS! Just to followup

If I change the lazy flag to false then cmp-dbee loads but I get the following error:

.../.local/share/nvim/lazy/cmp-dbee/lua/cmp-dbee/source.lua:147: attempt to call field 'is_core_loaded' (a nil value)

This is issue now fixed by #19 :)

However I'm stilling seeing the issue about lazy loading.

Thanks for reaching out @petobens I'll try to make some nice updates when I have time this weekend 😄

Let me know @petobens if you still see an error of this after checking out main.

Did some cleaning for the few time I had over but I need to make some more updates during the week. Let me know how it goes and we'll fix it.

Hi! I don't see an error anymore but for some reason cmp-dbee is not longer loaded. Whenever I open dbee o any sql file and run :CmpStatus I see:

# unknown source names
- cmp-dbee

and there is no completion from cmp-dbee. Any pointers?

Ahh, no I know. Let me fix this during the day after work. Sorry

Ok, so I pushed a small hotfix for this. Let me know if it doesn't work.

@petobens You need to update where you ref this plugin.
https://github.com/petobens/dotfiles/blob/master/nvim/lua/plugins.lua#L344-L355

it should be moved to the nvim-cmp as a dependency rather than nvim-dbee. Mainly because this plugin is dependent on nvim-dbee for the api calls 😋

Let me know if that does the trick!

Hi! I took a quick look and unfortunately couldn't make it work with your changes (btw you are missing a comma in the readme instructions after the dependecies and before the ft).
I'll have a further shot during the week and report back. Thanks!!

Hi @MattiasMTS I tried with the following minimal init.lua:

local root = '/tmp/nvim-minimal'

-- Set stdpaths to use root dir
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
    vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- Bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        'git',
        'clone',
        '--filter=blob:none',
        '--single-branch',
        'https://github.com/folke/lazy.nvim.git',
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

-- Install plugins
local plugins = {
    {
        'nvim-treesitter/nvim-treesitter',
        build = ':TSUpdate',
        config = function()
            require('nvim-treesitter.configs').setup({
                ensure_installed = { 'sql' },
            })
        end,
    },
    {
        'hrsh7th/nvim-cmp',
        dependencies = {
            'hrsh7th/cmp-buffer',
            'MattiasMTS/cmp-dbee',
        },
        config = function()
            local cmp = require('cmp')
            cmp.setup({
                completion = {
                    completeopt = 'menu,menuone,noinsert',
                },
                sources = {
                    { 'buffer' },
                    { 'cmp-dbee' },
                },
            })
        end,
    },
    {
        'kndndrj/nvim-dbee',
        dependencies = {
            'MunifTanjim/nui.nvim',
        },
        build = function()
            require('dbee').install()
        end,
        config = function()
            local dbee = require('dbee')
            dbee.setup({
                sources = {
                    require('dbee.sources').FileSource:new(
                        vim.env.HOME .. '/.config/.dbee_connections.json'
                    ),
                },
            })
            vim.keymap.set('n', ',db', dbee.toggle)
        end,
    },
}
require('lazy').setup(plugins, {
    root = root .. '/plugins',
})

and still cannot get :CmpStatus to report that cmp-dbee has loaded. Can you reproduce this?

Peek 2024-05-02 20-47

Hi @petobens , thanks for the extensive comment. Could you please checkout the branch #23 and see if that does the trick? :)

Hi @MattiasMTS unfortunately this is still not working for me. :CmpStatus doesn't report the cmp-dbee source.

Hi @MattiasMTS unfortunately this is still not working for me. :CmpStatus doesn't report the cmp-dbee source.

Ah ok, try adding opt = {} or config = function() require("cmp-dbee").setup({}) end to see if that does the trick. Because I'm registering the source in setup now rather than after.

Yep that did the trick! Thanks :)

Happy to hear. Sorry for dragging this on.

Not sure if I want this to be the default behaviour moving forward. It was at least the easiest to support configuration + other completion engines (if we want to, e.g. coc.nvim and mini.completion).

For now, I'll merge the updates branch and specify in the README how to run this. Thanks for taking your time on the feedback.

Thanks for the help and patience! :) Feel free to close this issue.