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

vsnip does not work with lsp #24

Closed
lourenci opened this issue Aug 15, 2021 · 10 comments
Closed

vsnip does not work with lsp #24

lourenci opened this issue Aug 15, 2021 · 10 comments

Comments

@lourenci
Copy link

How can I get vsnip to work with nvim-cmp-lsp?

plugins:

  use {
    'hrsh7th/nvim-cmp',
    after = 'nvim-lspconfig',
    config = function() require'config/nvim-compe' end,
  }
  use {
    'hrsh7th/cmp-nvim-lsp',
    after = 'nvim-cmp',
    config = function() require('cmp_nvim_lsp').setup {} end,
  }
  use {
    'hrsh7th/vim-vsnip',
    after = 'nvim-cmp',
  }
  use {
    'hrsh7th/vim-vsnip-integ',
    after = 'vim-vsnip',
  }

config:

local cmp = require'cmp'

cmp.setup {
  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(),
    ['<C-y>'] = cmp.mapping.confirm({
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,
    })
  },
  sources = {
    { name = 'nvim_lsp' }
  },
}

~/.vsnip/global.json:

{
  "diso": {
    "prefix": "diso",
    "body": ["${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}"],
    "description": "ISO date time stamp"
  }
}

results in a json file:
image

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 15, 2021

You should add { name = 'vsnip' } to sources.

@hrsh7th hrsh7th closed this as completed Aug 15, 2021
@hrsh7th
Copy link
Owner

hrsh7th commented Aug 15, 2021

BTW, Your reporting is much clear. Thanks!

@lourenci
Copy link
Author

lourenci commented Aug 15, 2021 via email

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 15, 2021

You don't need to set up vim-vsnip-integ. If you want to show vsnip candidates to completion-menu, You just add sources = { { name = 'nvim_lsp' }, { name = 'vsnip' } } both.

@lourenci
Copy link
Author

lourenci commented Aug 15, 2021 via email

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 15, 2021

The vim-vsnip-integ supports vim-lsp, vim-lsc, neovim builtin lsp omnifunc etc.

The nvim-cmp has a customizable snippet configuration point, so it is not needed.

@weizheheng
Copy link

Hi @hrsh7th, sorry for disturbing you.

I am migrating over from nvim-compe and having the same problem where nvim-cmp does not show snippets from vsnip + friendly-snippets. I have already added vsnip to the sources but it still does not work.

Appreciate if you can point me to debug further, thank you.

This is the config

local cmp = require 'cmp'
cmp.setup {
  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' },
  },
}

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 24, 2021

@marcushwz Did you install cmp-vsnip source via your plugin manager?

@weizheheng
Copy link

@hrsh7th, Didn't know about that. Just did that and it works now, thank you so much, and have a great day!

@learning2bdeveloper
Copy link

hey guys, i have problem that i can't use my custom snippet from ~/.vsnip/. please help me guys!

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

4 participants