Skip to content

Commit df10417

Browse files
mattnprabirshrestha
authored andcommitted
Comment for file_content
1 parent 0659ef1 commit df10417

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

autoload/lsp.vim

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

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

7+
" This hold previous content for each language servers to make
8+
" DidChangeTextDocumentParams. The key is buffer numbers:
9+
" {
10+
" 1: {
11+
" "golsp": [ "first-line", "next-line", ... ],
12+
" "bingo": [ "first-line", "next-line", ... ]
13+
" },
14+
" 2: {
15+
" "pyls": [ "first-line", "next-line", ... ]
16+
" }
17+
" }
718
let s:file_content = {}
819

920
" do nothing, place it here only to avoid the message
@@ -221,14 +232,14 @@ function! s:on_text_document_did_close() abort
221232
call lsp#log('s:on_text_document_did_close()', l:buf)
222233
endfunction
223234

224-
function! lsp#get_last_file_content(server_name, buf) abort
235+
function! s:get_last_file_content(server_name, buf) abort
225236
if has_key(s:file_content, a:buf) && has_key(s:file_content[a:buf], a:server_name)
226237
return s:file_content[a:buf][a:server_name]
227238
endif
228239
return []
229240
endfunction
230241

231-
function! lsp#update_file_content(server_name, buf, new) abort
242+
function! s:update_file_content(server_name, buf, new) abort
232243
if !has_key(s:file_content, a:buf)
233244
let s:file_content[a:buf] = {}
234245
endif
@@ -237,9 +248,7 @@ endfunction
237248

238249
function! s:on_buf_wipeout(buf) abort
239250
if has_key(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
251+
call remove(s:file_content, a:buf)
243252
endif
244253
endfunction
245254

@@ -436,16 +445,16 @@ function! s:text_changes(server_name, buf) abort
436445
" When syncKind is Incremental and previous content is saved.
437446
if l:sync_kind == 2 && has_key(s:file_content, a:buf)
438447
" compute diff
439-
let l:old_content = lsp#get_last_file_content(a:server_name, a:buf)
448+
let l:old_content = s:get_last_file_content(a:server_name, a:buf)
440449
let l:new_content = getbufline(a:buf, 1, '$')
441450
let l:changes = lsp#utils#diff#compute(l:old_content, l:new_content)
442-
call lsp#update_file_content(a:server_name, a:buf, l:new_content)
451+
call s:update_file_content(a:server_name, a:buf, l:new_content)
443452
return [l:changes]
444453
endif
445454

446455
let l:new_content = getbufline(a:buf, 1, '$')
447456
let l:changes = {'text': join(l:new_content, "\n")}
448-
call lsp#update_file_content(a:server_name, a:buf, l:new_content)
457+
call s:update_file_content(a:server_name, a:buf, l:new_content)
449458
return [l:changes]
450459
endfunction
451460

0 commit comments

Comments
 (0)