@@ -4,6 +4,8 @@ let s:servers = {} " { lsp_id, server_info, init_callbacks, init_result, buffers
4
4
5
5
let s: notification_callbacks = [] " { name, callback }
6
6
7
+ let s: file_content = {}
8
+
7
9
" do nothing, place it here only to avoid the message
8
10
augroup _lsp_silent_
9
11
autocmd !
@@ -219,9 +221,25 @@ function! s:on_text_document_did_close() abort
219
221
call lsp#log (' s:on_text_document_did_close()' , l: buf )
220
222
endfunction
221
223
224
+ function ! lsp#get_last_file_content (server_name, buf ) abort
225
+ if has_key (s: file_content , a: buf ) && has_key (s: file_content [a: buf ], a: server_name )
226
+ return s: file_content [a: buf ][a: server_name ]
227
+ endif
228
+ return []
229
+ endfunction
230
+
231
+ function ! lsp#update_file_content (server_name, buf , new ) abort
232
+ if ! has_key (s: file_content , a: buf )
233
+ let s: file_content [a: buf ] = {}
234
+ endif
235
+ let s: file_content [a: buf ][a: server_name ] = a: new
236
+ endfunction
237
+
222
238
function ! s: on_buf_wipeout (buf ) abort
223
239
if has_key (s: file_content , a: buf )
224
- call remove (s: file_content , a: buf )
240
+ for l: server_name in lsp#get_whitelisted_servers ()
241
+ call remove (s: file_content [a: buf ], l: server_name )
242
+ endfor
225
243
endif
226
244
endfunction
227
245
@@ -407,9 +425,8 @@ function! s:ensure_conf(buf, server_name, cb) abort
407
425
call a: cb (l: msg )
408
426
endfunction
409
427
410
- let s: file_content = {}
411
-
412
428
function ! s: text_changes (server_name, buf ) abort
429
+ echomsg a: server_name
413
430
let l: sync_kind = lsp#capabilities#get_text_document_change_sync_kind (a: server_name )
414
431
415
432
" When syncKind is None, return null for contentChanges.
@@ -420,16 +437,16 @@ function! s:text_changes(server_name, buf) abort
420
437
" When syncKind is Incremental and previous content is saved.
421
438
if l: sync_kind == 2 && has_key (s: file_content , a: buf )
422
439
" compute diff
423
- let l: old_content = get ( s: file_content , a: buf, [] )
440
+ let l: old_content = lsp#get_last_file_content ( a: server_name , a: buf )
424
441
let l: new_content = getbufline (a: buf , 1 , ' $' )
425
442
let l: changes = lsp#utils#diff#compute (l: old_content , l: new_content )
426
- let s: file_content [ a: buf] = l: new_content
443
+ call lsp#update_file_content ( a: server_name , a: buf, l: new_content)
427
444
return [l: changes ]
428
445
endif
429
446
430
447
let l: new_content = getbufline (a: buf , 1 , ' $' )
431
448
let l: changes = {' text' : join (l: new_content , " \n " )}
432
- let s: file_content [ a: buf] = l: new_content
449
+ call lsp#update_file_content ( a: server_name , a: buf, l: new_content)
433
450
return [l: changes ]
434
451
endfunction
435
452
0 commit comments