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

Snippet completion triggered without prefix #49

Closed
weizheheng opened this issue Aug 24, 2021 · 10 comments
Closed

Snippet completion triggered without prefix #49

weizheheng opened this issue Aug 24, 2021 · 10 comments

Comments

@weizheheng
Copy link

Working on migration from nvim-compe to here, and I have this issue, where snippet completions got triggered even when I haven't type anything yet.

Actual Behavior

  • Snippet completions got triggered without any prefix

  • Example in typescript
    image

  • Example in ruby
    image

Expected Behavior

  • I am expecting that snippets completion should only be triggered if I type in the prefix.

Config

local cmp = require 'cmp'
cmp.setup {
  completion = {
    completeopt = 'menu,menuone,noinsert'
  },
  snippet = {
    expand = function(args)
        vim.fn['vsnip#anonymous'](args.body)
    end
  },
  mapping = {
    ['<C-p>'] = cmp.mapping.prev_item(),
    ['<C-n>'] = cmp.mapping.next_item(),
    ['<C-d>'] = cmp.mapping.scroll(-4),
    ['<C-f>'] = cmp.mapping.scroll(4),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.close(),
    ['<CR>'] = cmp.mapping.confirm {
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,
    },
    ['<Tab>'] = cmp.mapping.mode({ 'i', 's' }, function(_, fallback)
      if vim.fn.pumvisible() == 1 then
        vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n')
      else
        fallback()
      end
    end),
    ['<S-Tab>'] = cmp.mapping.mode({ 'i', 's' }, function(_, fallback)
      if vim.fn.pumvisible() == 1 then
        vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n')
      else
        fallback()
      end
    end),
  },
  sources = {
    { name = 'nvim_lsp' },
    { name = 'vsnip' },
  },
}
@weizheheng weizheheng changed the title Snippet completion triggered when nothing is typed Snippet completion triggered without prefix Aug 24, 2021
@hrsh7th
Copy link
Owner

hrsh7th commented Aug 24, 2021

It's weird... I can't reproduce.

Anyway, you can set completion.autocomplete = { cmp.TriggerEvent.TextChanged } to avoid this.

@weizheheng
Copy link
Author

Thanks for the reply. I have added that but the same thing still happens.

  completion = {
    autocomplete = { cmp.TriggerEvent.TextChanged },
    completeopt = 'menu,menuone,noinsert'
  },

@weizheheng
Copy link
Author

weizheheng commented Aug 24, 2021

I tried debugging them a bit, and it seems like if the prefix contains any spaces then it will get triggered. Once i remove the spaces then it will not get triggered.

  "if else": {
    "prefix": "if else",
    "body": ["if ${1:test}", "\t$0", "else", "\t", "end"]
  },
  "if elsif": {
    "prefix": "if elsif",
    "body": ["if ${1:test}", "\t$0", "elsif ", "\t", "end"]
  },

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 24, 2021

OK. It seems a cmp-vsnip problem.

@weizheheng
Copy link
Author

I will close this issue then, do you want me to create one on cmp-vsnip?

For my use case now, I will just rename the prefix and delete those that I am not using.

Thanks again! Enjoying the new one so far, great work! :)

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 24, 2021

Hm... I'm investigating it now. It's a bit difficult 🤣

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 24, 2021

I've forgotten pushing local changes on cmp-vsnip 🤭

@abzcoding
Copy link
Contributor

i have a similar issue with luasnip as well, so I'm not sure the root cause is cmp-vsnip or not
image
and even if I do the following,
image

I'll get the same issue just after doing sth like permissions =

my configurations for reference

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 24, 2021

@abzcoding No. because cmp-vsnip issue is solved by cmp-vsnip's commit.
You should open issue to cmp-luasnip repo.

@abzcoding
Copy link
Contributor

cmp-luasnip

thank you, just added a PR and tested it locally saadparwaiz1/cmp_luasnip#3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants