mirror of
https://github.com/prabirshrestha/vim-lsp.git
synced 2025-12-14 20:35:59 +01:00
* fix comment
* fix indent
* support diagnostics in a floating window
* doc: add g:lsp_diagnostics_float_{cursor,delay}
* fix vint errors except unused variables
* suppress vint unused variable errors
* lint: use robust operator
63 lines
2.0 KiB
VimL
63 lines
2.0 KiB
VimL
let s:fixendofline_exists = exists('+fixendofline')
|
|
|
|
function! s:get_fixendofline(buf) abort
|
|
let l:eol = getbufvar(a:buf, '&endofline')
|
|
let l:binary = getbufvar(a:buf, '&binary')
|
|
|
|
if s:fixendofline_exists
|
|
let l:fixeol = getbufvar(a:buf, '&fixendofline')
|
|
|
|
if !l:binary
|
|
" When 'binary' is off and 'fixeol' is on, 'endofline' is not used
|
|
"
|
|
" When 'binary' is off and 'fixeol' is off, 'endofline' is used to
|
|
" remember the presence of a <EOL>
|
|
return l:fixeol || l:eol
|
|
else
|
|
" When 'binary' is on, the value of 'fixeol' doesn't matter
|
|
return l:eol
|
|
endif
|
|
else
|
|
" When 'binary' is off the value of 'endofline' is not used
|
|
"
|
|
" When 'binary' is on 'endofline' is used to remember the presence of
|
|
" a <EOL>
|
|
return !l:binary || l:eol
|
|
endif
|
|
endfunction
|
|
|
|
function! lsp#utils#buffer#_get_lines(buf) abort
|
|
let l:lines = getbufline(a:buf, 1, '$')
|
|
if s:get_fixendofline(a:buf)
|
|
let l:lines += ['']
|
|
endif
|
|
return l:lines
|
|
endfunction
|
|
|
|
" @params {location} = {
|
|
" 'uri': 'file://....',
|
|
" 'range': {
|
|
" 'start': { 'line': 1, 'character': 1 },
|
|
" 'end': { 'line': 1, 'character': 1 },
|
|
" }
|
|
" }
|
|
function! lsp#utils#buffer#_open_lsp_location(location) abort
|
|
let l:path = lsp#utils#uri_to_path(a:location['uri'])
|
|
let l:bufnr = bufnr(l:path)
|
|
|
|
let [l:start_line, l:start_col] = lsp#utils#position#_lsp_to_vim(l:bufnr, a:location['range']['start'])
|
|
let [l:end_line, l:end_col] = lsp#utils#position#_lsp_to_vim(l:bufnr, a:location['range']['end'])
|
|
|
|
normal! m'
|
|
if &modified && !&hidden
|
|
let l:cmd = l:bufnr !=# -1 ? 'sb ' . l:bufnr : 'split ' . fnameescape(l:path)
|
|
else
|
|
let l:cmd = l:bufnr !=# -1 ? 'b ' . l:bufnr : 'edit ' . fnameescape(l:path)
|
|
endif
|
|
execute l:cmd . ' | call cursor('.l:start_line.','.l:start_col.')'
|
|
|
|
normal! V
|
|
call setpos("'<", [l:bufnr, l:start_line, l:start_col])
|
|
call setpos("'>", [l:bufnr, l:end_line, l:end_col])
|
|
endfunction
|