@@ -405,17 +405,27 @@ endfunction
405
405
406
406
let s: file_content = {}
407
407
408
- function ! s: text_changes (buf ) abort
409
- if has_key (s: file_content , a: buf )
408
+ function ! s: text_changes (server_name, buf ) abort
409
+ let l: sync_kind = lsp#capabilities#get_text_document_change_sync_kind (a: server_name )
410
+
411
+ " When syncKind is None, return null for contentChanges.
412
+ if l: sync_kind == 0
413
+ return v: null
414
+ endif
415
+
416
+ " When syncKind is Incremental and previous content is saved.
417
+ if l: sync_kind == 2 && has_key (s: file_content , a: buf )
418
+ " compute diff
410
419
let l: old_content = get (s: file_content , a: buf , [])
411
420
let l: new_content = getbufline (a: buf , 1 , ' $' )
412
421
let l: changes = lsp#utils#diff#compute (l: old_content , l: new_content )
413
422
let s: file_content [a: buf ] = l: new_content
414
- else
415
- let l: new_content = getbufline (a: buf , 1 , ' $' )
416
- let l: changes = {' text' : join (l: new_content , " \n " )}
417
- let s: file_content [a: buf ] = l: new_content
423
+ return [l: changes ]
418
424
endif
425
+
426
+ let l: new_content = getbufline (a: buf , 1 , ' $' )
427
+ let l: changes = {' text' : join (l: new_content , " \n " )}
428
+ let s: file_content [a: buf ] = l: new_content
419
429
return [l: changes ]
420
430
endfunction
421
431
@@ -442,7 +452,7 @@ function! s:ensure_changed(buf, server_name, cb) abort
442
452
\ ' method' : ' textDocument/didChange' ,
443
453
\ ' params' : {
444
454
\ ' textDocument' : s: get_text_document_identifier (a: buf , l: buffer_info ),
445
- \ ' contentChanges' : s: text_changes (a: buf ),
455
+ \ ' contentChanges' : s: text_changes (a: server_name , a: buf ),
446
456
\ }
447
457
\ })
448
458
0 commit comments