Skip to content

Commit 9806023

Browse files
Adam Labbeprabirshrestha
authored andcommitted
Inspect buffer options to determine need for eol. (#158)
The eol option will be set if the vim found an eol at the eof. This, combined with the binary and fixeol options can be used to determine if the file will have eol characters at the end-of-file after vim saves the file.
1 parent 1366e07 commit 9806023

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

autoload/lsp.vim

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,17 @@ function! lsp#get_whitelisted_servers(...) abort
590590
return l:active_servers
591591
endfunction
592592

593+
function! s:requires_eol_at_eof(buf) abort
594+
let l:file_ends_with_eol = getbufvar(a:buf, '&eol')
595+
let l:vim_will_save_with_eol = !getbufvar(a:buf, '&binary') &&
596+
\ getbufvar(a:buf, '&fixeol')
597+
return l:file_ends_with_eol || l:vim_will_save_with_eol
598+
endfunction
599+
593600
function! s:get_text_document_text(buf) abort
594601
let l:buf_fileformat = getbufvar(a:buf, '&fileformat')
595-
let l:line_ending = {'unix': "\n", 'dos': "\r\n", 'mac': "\r"}[l:buf_fileformat]
596-
return join(getbufline(a:buf, 1, '$'), l:line_ending)
602+
let l:eol = {'unix': "\n", 'dos': "\r\n", 'mac': "\r"}[l:buf_fileformat]
603+
return join(getbufline(a:buf, 1, '$'), l:eol).(s:requires_eol_at_eof(a:buf) ? l:eol : '')
597604
endfunction
598605

599606
function! s:get_text_document(buf, buffer_info) abort

0 commit comments

Comments
 (0)