Code Monkey home page Code Monkey logo

Comments (10)

kristijanhusak avatar kristijanhusak commented on May 16, 2024 5

I'm also using Lazy. You can try my setup. Here's how I set up dadbod related stuff: https://github.com/kristijanhusak/neovim-config/blob/master/nvim/lua/partials/plugins/db.lua

And this is where I set up cmp for it: https://github.com/kristijanhusak/neovim-config/blob/master/nvim/lua/partials/plugins/completion.lua#L93-L106

from vim-dadbod-completion.

Zethtren avatar Zethtren commented on May 16, 2024 2

Thanks! It was not having the "cmd" line in my case. Apart from changing vsnip to luasnip copy pasting the second worked like a charm as well.

Reference solution for anyone else using LazyVim that finds this issue.

Thanks for the help and the great applications! @kristijanhusak
Keep up the great work!

-- plugins/cmp.lua
return {
  {
    "hrsh7th/nvim-cmp",
    lazy = true,
    opts = function(_, opts)
      local cmp = require("cmp")
      opts.completion = {
        completeopt = "menu,menuone,noinsert",
      }
      opts.window = {
        completion = cmp.config.window.bordered(),
        documentation = cmp.config.window.bordered(),
      }
      return opts
    end,
  },
}
-- plugins/dadbod.lua
return {
  {
    "kristijanhusak/vim-dadbod-ui",
    dependencies = {
      { "tpope/vim-dadbod", lazy = true },
      { "kristijanhusak/vim-dadbod-completion", lazy = true, ft = { "sql", "mysql", "plsql" } },
    },
    cmd = { "DBUI", "DBUIFindBuffer" },
  },
}
-- config/autocmds.lua
local autocomplete_group = vim.api.nvim_create_augroup("vimrc_autocompletion", { clear = true })
local cmp = require("cmp")
vim.api.nvim_create_autocmd("FileType", {
  pattern = { "sql", "mysql", "plsql" },
  callback = function()
    cmp.setup.buffer({
      sources = {
        { name = "vim-dadbod-completion" },
        { name = "buffer" },
        { name = "luasnip" },
      },
    })
  end,
  group = autocomplete_group,
})

from vim-dadbod-completion.

Zethtren avatar Zethtren commented on May 16, 2024

I have also had this issue.

return {
  {
    "tpope/vim-dadbod",
    dependencies = {
      "kristijanhusak/vim-dadbod-ui",
    },
  },
  {
    "kristijanhusak/vim-dadbod-ui",
  },
  -- {
  --   "kristijanhusak/vim-dadbod-completion",
  -- },
}

Commenting and uncommenting this line toggles the issue.

I am using LazyVim and my nvim-cmp config is completely default apart from a slight style choice.

return {
  {
    "hrsh7th/nvim-cmp",
    lazy = true,
    opts = function(_, opts)
      local cmp = require("cmp")
      opts.completion = {
        completeopt = "menu,menuone,noinsert",
      }
      opts.window = {
        completion = cmp.config.window.bordered(),
        documentation = cmp.config.window.bordered(),
      }
      return opts
    end,
  },
}

I would love this behavior inside of SQL editors but this just disables it globally for me.

I notice a strange behavior where it seems that nvim-cmp loading gets placed "behind" dadbod-completion when it is active.

-- `:Lazy profile` with dadbod-completion
      ➜  after 5.14ms
        ★   after/plugin/vim_dadbod_completion.lua 5.06ms
          ‒   nvim-cmp 4.53ms
            ●   crates.nvim 2.32ms
            ●   copilot-cmp 0.53ms
              ➜   copilot.lua 0.46ms
                ★   copilot.lua/plugin/copilot.lua 0.03ms
            ●   cmp-nvim-lsp 0.04ms
            ●   cmp-buffer 0.08ms
            ●   cmp-path 0.06ms
            ●   cmp_luasnip 0.07ms
            ●   nvim-cmp/plugin/cmp.lua 0.26ms
        ★   after/plugin/vim_dadbod_completion.vim 0.02ms

and removed from "InsertEnter" where I normally see it.
I'm not sure if the extension is taking ownership and overwriting the "event" somewhere. But something along those lines is what the behavior seems to suggest.

-- `:Lazy profile` without dadbod-completion
InsertEnter 21.42ms
      ➜   nvim-cmp 21.31ms
        ★   crates.nvim 10.62ms
          ‒   after/plugin/cmp_crates.lua 0.69ms
        ★   copilot-cmp 3ms
          ‒   copilot.lua 2.67ms
            ●   copilot.lua/plugin/copilot.lua 0.18ms
        ★   cmp-buffer 5.08ms
          ‒   after/plugin/cmp_buffer.lua 4.95ms
        ★   cmp-path 0.57ms
          ‒   after/plugin/cmp_path.lua 0.47ms
        ★   cmp_luasnip 0.66ms
          ‒   after/plugin/cmp_luasnip.lua 0.6ms
        ★   nvim-cmp/plugin/cmp.lua 0.27ms

from vim-dadbod-completion.

Zethtren avatar Zethtren commented on May 16, 2024

I noticed that my dependencies might have caused some confusion. dadbod requiring ui instead of the other way around.

I will invert these tomorrow and see if that fixes the issue on my end.

I tried reviewing all of the places where this extension interacts with cmp and nothing stood out as being a potential cause.

I will let you know if this corrects the behavior or if I find anything else.

from vim-dadbod-completion.

Napam avatar Napam commented on May 16, 2024

@kristijanhusak Thank you very much for the help. For me the solution was a little weird. I kept my code just the same, but the only thing I added was local cmp = require("cmp") (could be before or after the autocommand). That is, my code is this at the moment:

vim.api.nvim_create_autocmd("FileType", {
  pattern = { "sql", "mysql", "plsql" },
  command = ":lua require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} })",
})

local cmp = require("cmp")

I don't understand why requiring cmp as a local config variable solves anything. Doing this alone for example won't work:

vim.api.nvim_create_autocmd("FileType", {
  pattern = { "sql", "mysql", "plsql" },
  callback = function()
    require("cmp").setup.buffer({
      sources = {
        { name = "vim-dadbod-completion" },
        { name = "buffer" },
        { name = "luasnip" },
      },
    })
  end,
})

To make it work I MUST require cmp at some point in the code, for example:

vim.api.nvim_create_autocmd("FileType", {
  pattern = { "sql", "mysql", "plsql" },
  callback = function()
    require("cmp").setup.buffer({
      sources = {
        { name = "vim-dadbod-completion" },
        { name = "buffer" },
        { name = "luasnip" },
      },
    })
  end,
})

require("cmp") -- must have this

Maybe it is because LunarVim is doing something funny with cmp? I don't feel it is because of that, but at least this fixed my issue. Maybe doing require("cmp") initializes some stuff? But then why wont the require within the callback do the same?

Either way, thanks for the great plugins @kristijanhusak. They work really well.

from vim-dadbod-completion.

stale avatar stale commented on May 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from vim-dadbod-completion.

kristijanhusak avatar kristijanhusak commented on May 16, 2024

I'm closing this since it seems that everyone managed to solve the configuration issue.

from vim-dadbod-completion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.