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

My custom Vsnip completion mapping function no longer works since commit db261b4 #1149

Closed
2 tasks done
bluz71 opened this issue Aug 23, 2022 · 1 comment
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@bluz71
Copy link

bluz71 commented Aug 23, 2022

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-vsnip'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true })
  },

  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
  }),
}
EOF

function! VsnipComplete() abort
    let l:word_to_complete = matchstr(strpart(getline('.'), 0, col('.') - 1), '\S\+$')
    let l:contain_word = 'stridx(v:val.word, l:word_to_complete) >= 0'
    let l:candidates = vsnip#get_complete_items(bufnr('%'))
    let l:candidates = map(filter(l:candidates, l:contain_word),
                  \  "{
                  \      'word': v:val.word,
                  \      'menu': v:val.kind,
                  \      'dup' : 1,
                  \   }")
    let l:from_where = col('.') - len(l:word_to_complete)
    if !empty(l:candidates)
        call complete(l:from_where, l:candidates)
    endif

    return ''
endfunction

inoremap <silent> <C-s> <C-r>=VsnipComplete()<CR>

Description

Ever since commit db261b4 my custom <C-s> mapping no longer works.

Note, this is the same mapping that was provided in this Reddit post.

It appears the native popup menu quickly appears, then disappears (I think).

Steps to reproduce

Open a file with some vsnip snippets and then hit <Control-s> whilst in insert mode. Notice, no completion menu.

Now do the same with commit 27bc575. Notice, the completion menu appears (with snippets).

Expected behavior

Native completion menu should appear.

Actual behavior

Native completion does not appear (or is immediately closed).

Additional context

Hopefully it is just a simple tweak to the VsnipComplete function.

@bluz71 bluz71 added the bug Something isn't working label Aug 23, 2022
@bluz71
Copy link
Author

bluz71 commented Aug 23, 2022

Ok @hrsh7th, thanks for that.

Hopefully you find a longer-term fix.

Best regards.

williamboman added a commit to williamboman/nvim-cmp that referenced this issue Sep 23, 2022
…indow

* upstream/main: (36 commits)
  feat: add `filter` option to sources (hrsh7th#1067)
  Restore rockspec
  Fix grammar mistake: "setup" -> "set up" (hrsh7th#1155)
  fix(timer): close timers before Neovim exits (hrsh7th#1166)
  Add incsearch_redraw_keys settings (hrsh7th#1162)
  Fix hrsh7th#1149 (temporary fix)
  Fix hrsh7th#1146
  Re-fix hrsh7th#1144
  Fix hrsh7th#1144
  Fix hrsh7th#1142
  Fix hrsh7th#1135
  Fix onetime configuration handling
  fix(entry/get_replace_range): handle TextEdit.range (hrsh7th#1140)
  Refactor a bit
  Restore filetype setting
  Fix hrsh7th#1139
  Add FAQ for clangd's command-line arguments. Fixes hrsh7th#999
  The default highlight groups shouldn't be default=true. Fixes hrsh7th#972
  Fix hrsh7th#1102
  Use `cmp.config.sources` (hrsh7th#1105)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant