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

[Feature Request] Add a way to configure cmp_select_opts #101

Closed
dylanpjx opened this issue Dec 29, 2022 · 6 comments
Closed

[Feature Request] Add a way to configure cmp_select_opts #101

dylanpjx opened this issue Dec 29, 2022 · 6 comments

Comments

@dylanpjx
Copy link

It would be very helpful to have this as a top level configuration and not need to add mappings to override the select opts. Thanks!

@VonHeikemen
Copy link
Owner

There is a way. Change the preset to lsp-compe. Then you can configure nvim-cmp however you like. You can use the function .defaults.cmp_config to extend/change the defaults lsp-zero offers and pass that to nvim-cmp.

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

lsp.setup()

vim.opt.completeopt = {'menu', 'menuone', 'noselect'}

local cmp = require('cmp')
local cmp_config = lsp.defaults.cmp_config({
  ---
  -- nvim-cmp options go here
  ---
})

cmp.setup(cmp_config)

@VonHeikemen
Copy link
Owner

Wait. You mean the select behavior when you move between items?

@dylanpjx
Copy link
Author

Afaik, that would still require one to re-add mappings and change/insert cmp.SelectBehavior per mapping manually right?

It would be great if lspzero had a global option that could be set at the top level.

@VonHeikemen
Copy link
Owner

It would be lovely if nvim-cmp had that feature.

Okay. I've added select_behavior option to .setup_nvim_cmp.

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

lsp.setup_nvim_cmp({
  select_behavior = 'insert'
})

lsp.setup()

Is worth mention the default in lsp-zero is the first item gets "preselected", but it seems the text won't be inserted in this case. It'll only start putting text in the buffer when you start navigating between items.

If you disable the preselect you'll get something more consistent.

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

lsp.setup_nvim_cmp({
  select_behavior = 'insert',
  preselect = 'none',
  completion = {
    completeopt = 'menu,menuone,noinsert,noselect'
  },
})

lsp.setup()

@dylanpjx
Copy link
Author

Wow, thanks for the fast patch! 😄

@VonHeikemen
Copy link
Owner

Global variables FTW!

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