1
1
" vint: -ProhibitUnusedVariable
2
2
3
3
" constants {{{
4
+ let s: t_dict = type ({})
4
5
5
6
let s: default_completion_item_kinds = {
6
7
\ ' 1' : ' text' ,
@@ -232,14 +233,14 @@ function! s:send_completion_request(info) abort
232
233
let l: server_name = a: info [' server_names' ][0 ]
233
234
" TODO: support multiple servers
234
235
call lsp#send_request (l: server_name , {
235
- \ ' method' : ' textDocument/completion' ,
236
- \ ' params' : {
237
- \ ' textDocument' : lsp#get_text_document_identifier (),
238
- \ ' position' : lsp#get_position (),
239
- \ ' context' : { ' triggerKind' : 1 },
240
- \ },
241
- \ ' on_notification' : function (' s:handle_omnicompletion' , [l: server_name , s: completion [' counter' ], a: info ]),
242
- \ })
236
+ \ ' method' : ' textDocument/completion' ,
237
+ \ ' params' : {
238
+ \ ' textDocument' : lsp#get_text_document_identifier (),
239
+ \ ' position' : lsp#get_position (),
240
+ \ ' context' : { ' triggerKind' : 1 },
241
+ \ },
242
+ \ ' on_notification' : function (' s:handle_omnicompletion' , [l: server_name , s: completion [' counter' ], a: info ]),
243
+ \ })
243
244
endfunction
244
245
245
246
function ! s: get_completion_result (server_name, data) abort
@@ -256,82 +257,6 @@ function! s:get_completion_result(server_name, data) abort
256
257
return {' matches' : l: completion_result [' items' ], ' incomplete' : l: completion_result [' incomplete' ] }
257
258
endfunction
258
259
259
- function ! s: get_vim_completion_item (item, options ) abort
260
- let l: server_name = a: options [' server' ][' name' ]
261
- let l: complete_position = a: options [' position' ]
262
- let l: kind_text_mappings = a: options [' kind_text_mappings' ]
263
-
264
- let l: word = ' '
265
- let l: expandable = v: false
266
- if get (a: item , ' insertTextFormat' , -1 ) == 2 && ! empty (get (a: item , ' insertText' , ' ' ))
267
- " if candidate is snippet, use insertText. But it may include
268
- " placeholder.
269
- let l: word = lsp#utils#make_valid_word (a: item [' insertText' ])
270
- let l: expandable = l: word !=# a: item [' insertText' ]
271
- elseif ! empty (get (a: item , ' insertText' , ' ' ))
272
- " if plain-text insertText, use it.
273
- let l: word = a: item [' insertText' ]
274
- elseif has_key (a: item , ' textEdit' ) && type (a: item [' textEdit' ]) == # v: t_dict
275
- let l: word = lsp#utils#make_valid_word (a: item [' label' ])
276
- let l: expandable = l: word !=# get (a: item [' textEdit' ], ' newText' , ' ' )
277
- endif
278
- if ! empty (l: word )
279
- let l: word = split (l: word , ' \n' )[0 ]
280
- endif
281
- if empty (l: word )
282
- let l: word = a: item [' label' ]
283
- endif
284
- let l: abbr = a: item [' label' ]
285
-
286
- if has_key (a: item , ' insertTextFormat' ) && a: item [' insertTextFormat' ] == 2
287
- let l: word = substitute (l: word , ' \$[0-9]\+\|\${\%(\\.\|[^}]\)\+}' , ' ' , ' g' )
288
- endif
289
-
290
- let l: word = lsp#utils#_trim (l: word )
291
- let l: kind = has_key (a: item , ' kind' ) ? get (l: kind_text_mappings , a: item [' kind' ], ' ' ) : ' '
292
-
293
- let l: completion = {
294
- \ ' word' : l: word ,
295
- \ ' abbr' : l: abbr . (l: expandable ? ' ~' : ' ' ),
296
- \ ' menu' : ' ' ,
297
- \ ' info' : ' ' ,
298
- \ ' icase' : 1 ,
299
- \ ' dup' : 1 ,
300
- \ ' empty' : 1 ,
301
- \ ' kind' : l: kind ,
302
- \ }
303
-
304
- " check support user_data.
305
- " if not support but g:lsp_text_edit_enabled enabled,
306
- " then print information to user and add information to log file.
307
- if ! s: is_user_data_support && g: lsp_text_edit_enabled
308
- let l: no_support_error_message = ' textEdit support on omni complete requires Vim 8.0 patch 1493 or later(please check g:lsp_text_edit_enabled)'
309
- call lsp#utils#error (l: no_support_error_message )
310
- call lsp#log (l: no_support_error_message )
311
- endif
312
-
313
- " Add user_data.
314
- if s: is_user_data_support
315
- let l: completion [' user_data' ] = s: create_user_data (a: item , l: server_name , l: complete_position )
316
- endif
317
-
318
- if has_key (a: item , ' detail' ) && ! empty (a: item [' detail' ])
319
- let l: completion [' menu' ] = substitute (a: item [' detail' ], ' [ \t\n\r]\+' , ' ' , ' g' )
320
- endif
321
-
322
- if has_key (a: item , ' documentation' )
323
- if type (a: item [' documentation' ]) == type (' ' ) " field is string
324
- let l: completion [' info' ] .= a: item [' documentation' ]
325
- elseif type (a: item [' documentation' ]) == type ({}) &&
326
- \ has_key (a: item [' documentation' ], ' value' )
327
- " field is MarkupContent (hopefully 'plaintext')
328
- let l: completion [' info' ] .= substitute (a: item [' documentation' ][' value' ], ' \r' , ' ' , ' g' )
329
- endif
330
- endif
331
-
332
- return l: completion
333
- endfunction
334
-
335
260
" options = {
336
261
" server: {}, " needs to be server_info and not server_name
337
262
" position: lsp#get_position(),
@@ -340,6 +265,8 @@ endfunction
340
265
" }
341
266
function ! lsp#omni#get_vim_completion_items (options ) abort
342
267
let l: server = a: options [' server' ]
268
+ let l: server_name = l: server [' name' ]
269
+ let l: kind_text_mappings = s: get_kind_text_mappings (l: server )
343
270
let l: complete_position = a: options [' position' ]
344
271
345
272
let l: result = a: options [' response' ][' result' ]
@@ -355,14 +282,33 @@ function! lsp#omni#get_vim_completion_items(options) abort
355
282
endif
356
283
357
284
let l: vim_complete_items = []
358
- let l: server_name = l: server [' name' ]
359
- let l: item_options = {
360
- \ ' server' : l: server ,
361
- \ ' position' : l: complete_position ,
362
- \ ' kind_text_mappings' : s: get_kind_text_mappings (l: server ),
363
- \ }
364
- for l: item in l: items
365
- call add (l: vim_complete_items , s: get_vim_completion_item (l: item , l: item_options ))
285
+ for l: completion_item in l: items
286
+ let l: expandable = get (l: completion_item , ' insertTextFormat' , 1 ) == 2
287
+ let l: vim_complete_item = {
288
+ \ ' kind' : get (l: kind_text_mappings , get (l: completion_item , ' kind' , ' ' ) , ' ' ),
289
+ \ ' dup' : 1 ,
290
+ \ ' empty' : 1 ,
291
+ \ ' icase' : 1 ,
292
+ \ }
293
+ if has_key (l: completion_item , ' textEdit' ) && type (l: completion_item [' textEdit' ]) == type (s: t_dict ) && has_key (l: completion_item [' textEdit' ], ' nextText' )
294
+ let l: vim_complete_item [' word' ] = l: completion_item [' textEdit' ][' nextText' ]
295
+ elseif has_key (l: completion_item , ' insertText' ) && ! empty (l: completion_item [' insertText' ])
296
+ let l: vim_complete_item [' word' ] = l: completion_item [' insertText' ]
297
+ else
298
+ let l: vim_complete_item [' word' ] = l: completion_item [' label' ]
299
+ endif
300
+
301
+ if l: expandable
302
+ let l: vim_complete_item [' abbr' ] = l: completion_item [' label' ] . ' ~'
303
+ else
304
+ let l: vim_complete_item [' abbr' ] = l: completion_item [' label' ]
305
+ endif
306
+
307
+ if s: is_user_data_support
308
+ let l: vim_complete_item [' user_data' ] = s: create_user_data (l: completion_item , l: server_name , l: complete_position )
309
+ endif
310
+
311
+ let l: vim_complete_items += [l: vim_complete_item ]
366
312
endfor
367
313
368
314
return { ' items' : l: vim_complete_items , ' incomplete' : l: incomplete }
@@ -428,5 +374,4 @@ endfunction
428
374
function ! s: create_user_data_key (base) abort
429
375
return ' {"vim-lsp/key":"' . a: base . ' "}'
430
376
endfunction
431
-
432
377
" }}}
0 commit comments