Skip to content

Commit 84c8dd9

Browse files
mattnprabirshrestha
authored andcommitted
Hold file content per servers
1 parent 27756be commit 84c8dd9

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

autoload/lsp.vim

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ let s:servers = {} " { lsp_id, server_info, init_callbacks, init_result, buffers
44

55
let s:notification_callbacks = [] " { name, callback }
66

7+
let s:file_content = {}
8+
79
" do nothing, place it here only to avoid the message
810
augroup _lsp_silent_
911
autocmd!
@@ -219,9 +221,25 @@ function! s:on_text_document_did_close() abort
219221
call lsp#log('s:on_text_document_did_close()', l:buf)
220222
endfunction
221223

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+
222238
function! s:on_buf_wipeout(buf) abort
223239
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
225243
endif
226244
endfunction
227245

@@ -407,9 +425,8 @@ function! s:ensure_conf(buf, server_name, cb) abort
407425
call a:cb(l:msg)
408426
endfunction
409427

410-
let s:file_content = {}
411-
412428
function! s:text_changes(server_name, buf) abort
429+
echomsg a:server_name
413430
let l:sync_kind = lsp#capabilities#get_text_document_change_sync_kind(a:server_name)
414431

415432
" When syncKind is None, return null for contentChanges.
@@ -420,16 +437,16 @@ function! s:text_changes(server_name, buf) abort
420437
" When syncKind is Incremental and previous content is saved.
421438
if l:sync_kind == 2 && has_key(s:file_content, a:buf)
422439
" 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)
424441
let l:new_content = getbufline(a:buf, 1, '$')
425442
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)
427444
return [l:changes]
428445
endif
429446

430447
let l:new_content = getbufline(a:buf, 1, '$')
431448
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)
433450
return [l:changes]
434451
endfunction
435452

0 commit comments

Comments
 (0)