File tree Expand file tree Collapse file tree 4 files changed +72
-0
lines changed Expand file tree Collapse file tree 4 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ VSCode(LSP)'s snippet feature in vim/nvim.
23
23
- [ vimcomplete] ( https://github.com/girishji/vimcomplete )
24
24
- [ ddc.vim] ( https://github.com/Shougo/ddc.vim )
25
25
- [ vim-easycompletion] ( https://github.com/jayli/vim-easycomplete )
26
+ - Support built-in completion
27
+ - A function can be registered for finding completions.
28
+ ` set complete+=Fvsnip#completefunc `
26
29
- Vim script interpolation
27
30
- You can use Vim script interpolation as ` ${VIM:...Vim script expression...} ` .
28
31
- SnipMate-like syntax support
Original file line number Diff line number Diff line change @@ -166,6 +166,25 @@ function! vsnip#get_context() abort
166
166
return {}
167
167
endfunction
168
168
169
+ "
170
+ " vsnip#completefunc
171
+ "
172
+ function ! vsnip#completefunc (findstart, base) abort
173
+ if ! a: findstart
174
+ if a: base == # ' '
175
+ return []
176
+ endif
177
+ return vsnip#get_complete_items (bufnr (' %' ))
178
+ endif
179
+
180
+ let line = getline (' .' )
181
+ let start = col (' .' ) - 2
182
+ while start >= 0 && line [start ] = ~# ' \k'
183
+ let start -= 1
184
+ endwhile
185
+ return start + 1
186
+ endfunction
187
+
169
188
"
170
189
" vsnip#get_complete_items
171
190
"
Original file line number Diff line number Diff line change @@ -117,7 +117,12 @@ FUNCTION *vsnip-function*
117
117
118
118
Register your own custom variable resolver.
119
119
120
+ vsnip#completefunc()
120
121
122
+ Register for finding completions.
123
+ >
124
+ set complete+=Fvsnip#completefunc
125
+ <
121
126
122
127
==============================================================================
123
128
MAPPING *vsnip-mapping*
Original file line number Diff line number Diff line change @@ -145,5 +145,50 @@ Describe vsnip
145
145
146
146
End
147
147
148
+ Describe #completefunc
149
+
150
+ It should return start position
151
+ enew!
152
+ set filetype=basic_spec
153
+ call setline(1, ' if')
154
+ call cursor([1, 3])
155
+ call s:expect(vsnip#completefunc(1, '')).to_equal(1)
156
+ End
157
+
158
+ It should return complete items
159
+ enew!
160
+ set filetype=basic_spec
161
+ call s:expect(vsnip#completefunc(0, 'if')[-1]).to_equal({
162
+ \ 'word': 'if',
163
+ \ 'abbr': 'if',
164
+ \ 'kind': 'Snippet',
165
+ \ 'menu': '[v] if',
166
+ \ 'dup': 1,
167
+ \ 'user_data': json_encode({
168
+ \ 'vsnip': {
169
+ \ 'snippet': [
170
+ \ "if ${1:condition}",
171
+ \ "\t$0",
172
+ \ "endif",
173
+ \ ]
174
+ \ }
175
+ \ })
176
+ \ }, {
177
+ \ 'word': 'inline-fn',
178
+ \ 'abbr': 'inline-fn',
179
+ \ 'kind': 'Snippet',
180
+ \ 'menu': '[v] inline-fn',
181
+ \ 'dup': 1,
182
+ \ 'user_data': json_encode({
183
+ \ 'vsnip': {
184
+ \ 'snippet': [
185
+ \ "{ -> $1 }$0"
186
+ \ ]
187
+ \ }
188
+ \ })
189
+ \ })
190
+ End
191
+ End
192
+
148
193
End
149
194
You can’t perform that action at this time.
0 commit comments