cmp-dbee icon indicating copy to clipboard operation
cmp-dbee copied to clipboard

Unable to get completion working

Open kade5 opened this issue 1 year ago • 11 comments

Hello,

I'm unable to get completion working. Lazy shows the plugin as loaded, but running :Cmpstatus shows cmp-dbee under "unknown source names".

My configuration can be found here https://github.com/kade5/kickstart.nvim/tree/dbee and my nvim-cmp configuration is on lines 653 to 770 in init.lua. See below.

I was able to get completion working using commit 0feabc1, but it doesn't work starting with commit 67976ff.

 { -- Autocompletion
    'hrsh7th/nvim-cmp',
    event = 'InsertEnter',
    dependencies = {
      -- Snippet Engine & its associated nvim-cmp source
      {
        'L3MON4D3/LuaSnip',
        build = (function()
          if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
            return
          end
          return 'make install_jsregexp'
        end)(),
        dependencies = {
        },
      },
      'saadparwaiz1/cmp_luasnip',

      'hrsh7th/cmp-nvim-lsp',
      'hrsh7th/cmp-path',
      {
        'MattiasMTS/cmp-dbee',
        commit = '0feabc1', --completion works using this commit
        dependencies = {
          { 'kndndrj/nvim-dbee' },
        },
        ft = 'sql',
      },
    },
    config = function()
      -- See `:help cmp`
      local cmp = require 'cmp'
      local luasnip = require 'luasnip'
      luasnip.config.setup {}

      cmp.setup {
        snippet = {
          expand = function(args)
            luasnip.lsp_expand(args.body)
          end,
        },
        completion = { completeopt = 'menu,menuone,noinsert' },

        mapping = cmp.mapping.preset.insert {
          -- Select the [n]ext item
          ['<C-n>'] = cmp.mapping.select_next_item(),
          -- Select the [p]revious item
          ['<C-p>'] = cmp.mapping.select_prev_item(),

          -- Scroll the documentation window [b]ack / [f]orward
          ['<C-b>'] = cmp.mapping.scroll_docs(-4),
          ['<C-f>'] = cmp.mapping.scroll_docs(4),

          ['<C-y>'] = cmp.mapping.confirm { select = true },

          ['<C-Space>'] = cmp.mapping.complete {},

          ['<C-l>'] = cmp.mapping(function()
            if luasnip.expand_or_locally_jumpable() then
              luasnip.expand_or_jump()
            end
          end, { 'i', 's' }),
          ['<C-h>'] = cmp.mapping(function()
            if luasnip.locally_jumpable(-1) then
              luasnip.jump(-1)
            end
          end, { 'i', 's' }),

        },
        sources = {
          { name = 'nvim_lsp' },
          { name = 'luasnip' },
          { name = 'path' },
          { name = 'cmp-dbee' },
        },
      }
    end,
  },

kade5 avatar May 04 '24 20:05 kade5

Hi @kade5 thanks for the extensive issue.

Nice to hear you made it work by using the previous commit. Perhaps that solves issue #18 as well.

Let me do some more tests later tonight or tomorrow to decide if I'm going to revert the is_available part by just using the after/ loading.

Again, thanks!

MattiasMTS avatar May 05 '24 16:05 MattiasMTS

Hi @kade5 please checkout the branch #23 and see if that does the trick!

MattiasMTS avatar May 06 '24 15:05 MattiasMTS

Hi @kade5 Try adding opt = {} or config = function() require("cmp-dbee").setup({}) end to see if that does the trick.

MattiasMTS avatar May 06 '24 15:05 MattiasMTS

Hi @MattiasMTS,

Thanks for all the work you're doing! completion works for me when I use the ms/updates branch #23 , and it also works on the main branch when I add config = function() require("cmp-dbee").setup({}) end to my config.

kade5 avatar May 06 '24 23:05 kade5

Testing out your other suggestion, If I use the main branch and add just opt = {}, without the config = function() part it does not work.

kade5 avatar May 06 '24 23:05 kade5

Ah sorry, I meant opts = {} instead of opt. Glad to hear it worked out! Closing this now 😋

MattiasMTS avatar May 07 '24 10:05 MattiasMTS

@kade5 @MattiasMTS hello, guys! 👋

Same thing happening to me. I'm trying from commit 9b0b969 (most recent changes from master branch until now).

It doesn't work even with:

config = function() require("cmp-dbee").setup({}) end

Screenshot: image

CmpStatus output: image

OBS: I also tried with opts = {} (not opt)

Hugobsb avatar May 09 '24 23:05 Hugobsb

Hi @MattiasMTS after #23 the plugin stopped working even when adding an explict require('cmp-dbee').setup() call. When I open a sql file I see: image

petobens avatar May 15 '24 20:05 petobens

Hi @MattiasMTS after #23 the plugin stopped working even when adding an explict require('cmp-dbee').setup() call.

Thanks for highlighting it. cd409ef was the fix.

Accidentally forgot to remove the after setup. Hope that does the trick.

@Hugobsb could you send a screenshot of your setup? I'm wondering if you've the nvim-dbee and cmp-dbee dependency setup correctly since we have this https://github.com/MattiasMTS/cmp-dbee/blob/main/lua/cmp-dbee/source.lua#L6 which requires nvim-dbee to be loaded before cmp-dbee.

MattiasMTS avatar May 16 '24 04:05 MattiasMTS

Accidentally forgot to remove the after setup. Hope that does the trick.

Yes! Thanks!

petobens avatar May 16 '24 11:05 petobens

Hi @MattiasMTS after #23 the plugin stopped working even when adding an explict require('cmp-dbee').setup() call.

Thanks for highlighting it. cd409ef was the fix.

Accidentally forgot to remove the after setup. Hope that does the trick.

@Hugobsb could you send a screenshot of your setup? I'm wondering if you've the nvim-dbee and cmp-dbee dependency setup correctly since we have this https://github.com/MattiasMTS/cmp-dbee/blob/main/lua/cmp-dbee/source.lua#L6 which requires nvim-dbee to be loaded before cmp-dbee.

Hi, @MattiasMTS! Thanks for the support.

About the screenshot, sure! Everything is public and available here.

Hugobsb avatar May 16 '24 14:05 Hugobsb

image All of this fixed the original issue. However, now it is an unavailable source name. Same as @Hugobsb issue

https://github.com/MattiasMTS/cmp-dbee/blob/cd409ef1256a470849860ef3f476d95be2789883/lua/cmp-dbee/source.lua#L6

The above line is false until dbee is opened.

Tired-Fox avatar May 30 '24 20:05 Tired-Fox

If I set is_available to be true everything works

Tired-Fox avatar May 30 '24 21:05 Tired-Fox

If I set is_available to be true everything works

Same for me. I ended up moving the setting of the is_available into the constructor as a member function of the source class

--- Constructor for nvim-cmp source
---@param cfg Config
function source:new(cfg)
  local is_available = self:is_available()
  local cls = { handler = handler:new(cfg, is_available) }
  setmetatable(cls, self)
  self.__index = self
  return cls
end

-- and some code...

function source:is_available()
  return dbee.api.core.is_loaded() and dbee.api.ui.is_loaded()
end

And then I had to call the setup({}) after I had opened dbee to make this true.

@MattiasMTS , what would be a good solution for this, I can make a PR to fix this tomorrow using this approach if wanted?

Edit: See that you added the is_available in the constructor of the handler in commit a40b22c668c9. Think the only problem now is how that variable is now set before dbee is available? Which is solved by the above code snippet.

phdah avatar Jul 08 '24 20:07 phdah