Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ VSCode(LSP)'s snippet feature in vim/nvim.
- [vimcomplete](https://github.com/girishji/vimcomplete)
- [ddc.vim](https://github.com/Shougo/ddc.vim)
- [vim-easycompletion](https://github.com/jayli/vim-easycomplete)
- Support built-in completion
- A function can be registered for finding completions.
`set complete+=Fvsnip#completefunc`
- Vim script interpolation
- You can use Vim script interpolation as `${VIM:...Vim script expression...}`.
- SnipMate-like syntax support
Expand Down
19 changes: 19 additions & 0 deletions autoload/vsnip.vim
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ function! vsnip#get_context() abort
return {}
endfunction

"
" vsnip#completefunc
"
function! vsnip#completefunc(findstart, base) abort
if !a:findstart
if a:base ==# ''
return []
endif
return vsnip#get_complete_items(bufnr('%'))
endif

let line = getline('.')
let start = col('.') - 2
while start >= 0 && line[start] =~# '\k'
let start -= 1
endwhile
return start + 1
endfunction

"
" vsnip#get_complete_items
"
Expand Down
5 changes: 5 additions & 0 deletions doc/vsnip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ FUNCTION *vsnip-function*

Register your own custom variable resolver.

vsnip#completefunc()

Register for finding completions.
>
set complete+=Fvsnip#completefunc
<

==============================================================================
MAPPING *vsnip-mapping*
Expand Down
45 changes: 45 additions & 0 deletions spec/autoload/vsnip.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,50 @@ Describe vsnip

End

Describe #completefunc

It should return start position
enew!
set filetype=basic_spec
call setline(1, ' if')
call cursor([1, 3])
call s:expect(vsnip#completefunc(1, '')).to_equal(1)
End

It should return complete items
enew!
set filetype=basic_spec
call s:expect(vsnip#completefunc(0, 'if')[-1]).to_equal({
\ 'word': 'if',
\ 'abbr': 'if',
\ 'kind': 'Snippet',
\ 'menu': '[v] if',
\ 'dup': 1,
\ 'user_data': json_encode({
\ 'vsnip': {
\ 'snippet': [
\ "if ${1:condition}",
\ "\t$0",
\ "endif",
\ ]
\ }
\ })
\ }, {
\ 'word': 'inline-fn',
\ 'abbr': 'inline-fn',
\ 'kind': 'Snippet',
\ 'menu': '[v] inline-fn',
\ 'dup': 1,
\ 'user_data': json_encode({
\ 'vsnip': {
\ 'snippet': [
\ "{ -> $1 }$0"
\ ]
\ }
\ })
\ })
End
End

End

Loading