Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass completion option through to nvim-cmp #7

Closed
Aaronik opened this issue Mar 24, 2022 · 4 comments
Closed

How to pass completion option through to nvim-cmp #7

Aaronik opened this issue Mar 24, 2022 · 4 comments

Comments

@Aaronik
Copy link

Aaronik commented Mar 24, 2022

Is there a way to pass the { 'completion.autocomplete' } option through to cmp? I'm trying to get a debounce on my completion, which led me to hrsh7th/nvim-cmp#598, which requires a config param (autocomplete) be passed in to cmp before cmp.setup() is called. Looks like cmp documents a similar approach to a problem here.

I see your documentation of setup_nvim_cmp but I'm not clearly understanding from the docs whether the completion list will be passed in, and in my attempts to make it work, it is not working.

P.S. Thank you for making this tool! I'm fresh in the nvim world from vim and this tool has really eased my transition.

@Aaronik Aaronik changed the title How to pass config options through to lsp-cmp How to pass config options through to nvim-cmp Mar 24, 2022
@Aaronik Aaronik changed the title How to pass config options through to nvim-cmp How to pass completion option through to nvim-cmp Mar 24, 2022
@VonHeikemen
Copy link
Owner

completion was not exposed. But since 81e3d1f you can overwrite it if you want.

This should work now.

local lsp = require('lsp-zero')
lsp.preset('recommended')

lsp.setup_nvim_cmp({
  completion = { autocomplete = false }
})

lsp.setup()

@Aaronik
Copy link
Author

Aaronik commented Mar 25, 2022

Thank you for your lightening fast response!

I've updated your plugin in my setup (Using plug, so I ran :PlugUpdate). I saw that lsp-zero was updated. I also went to the ~/.vim/plugged/lsp-zero folder and checked the git history, and the 81e3d1f commit was there, in addition to a couple more.

I have a series of lsp calls in my lua config: lsp.set_preferences(...), lsp.on_attach(...), lsp.setup_nvim_cmp(...). Here is the relevant config:

local lspz = require('lsp-zero')

lspz.set_preferences({
  suggest_lsp_servers = true,
  setup_servers_on_start = true,
  set_lsp_keymaps = false, -- Toggled b/c the defaults are alright but not great for me.
  configure_diagnostics = true,
  cmp_capabilities = true,
  manage_nvim_cmp = true,
  call_servers = 'local',
  sign_icons = {
    error = '',
    warn = '',
    hint = '',
    info = ''
  }
})

lspz.on_attach(function()
  local noremap = {noremap = true}
  local map = function(...) vim.api.nvim_buf_set_keymap(0, ...) end

  map('n', '<leader>je', '<cmd>lua vim.lsp.buf.rename()<cr>', noremap)
  map('n', '<leader>jk', '<cmd>lua vim.lsp.buf.hover()<cr>', noremap)
  map('n', '<leader>jd', '<cmd>lua vim.lsp.buf.definition()<cr>', noremap)
  map('n', '<leader>jD', '<cmd>lua vim.lsp.buf.declaration()<cr>', noremap)
  map('n', '<leader>jt', '<cmd>lua vim.lsp.buf.type_definition()<cr>', noremap)
  map('n', '<leader>ji', '<cmd>lua vim.lsp.buf.implementation()<cr>', noremap)
  map('n', '<leader>jr', '<cmd>lua vim.lsp.buf.references()<cr>', noremap)
  map('n', '<leader>js', '<cmd>lua vim.lsp.buf.signature_help()<cr>', noremap)
  map('n', '<leader>ja', '<cmd>lua vim.lsp.buf.code_action()<cr>', noremap)
  map('n', '<leader>jf', '<cmd>lua LspZeroFormat<cr>', noremap)
  map('n', '<leader>jw', '<cmd>lua vim.diagnostic.open_float()<cr>', noremap)
  map('n', '<C-l>', '<cmd>lua vim.diagnostic.goto_prev()<cr>', noremap)
  map('n', '<C-h>', '<cmd>lua vim.diagnostic.goto_next()<cr>', noremap)
end)

lspz.setup_nvim_cmp({
  completion = { autocomplete = false }
})

lspz.setup()

However I'm still seeing autocompletion. Am I doing anything obviously wrong?

@VonHeikemen
Copy link
Owner

It works for me.

Could it be another plugin or old configuration code still around?

Side note: <leader>jf is not going to work. LspZeroFormat is a vim command not a lua function. You should bind it to <cmd>lua vim.lsp.buf.formatting()<cr>.

@Aaronik
Copy link
Author

Aaronik commented Mar 25, 2022

Ah oh nice, thank you for the heads up about jf, you're right that totally will not work.

I'm not really sure, I'll keep looking into it and if I find an answer I'll come back and post. Thanks for your help!

UPDATE: User error all the way. In figuring out where I was going to house my rc/init scripts and just generally getting it all working, I forgot to make a sym link to a file and was editing one in the wrong directory. Works now like a charm.

@Aaronik Aaronik closed this as completed Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants