]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/vim-lsp/autoload/lsp/utils/buffer.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit 'd49e95aa7ba744f0a7f544aca43afdb6aab41f24' as '.vim/bundle/asyncomplete...
[etc/vim.git] / .vim / bundle / vim-lsp / autoload / lsp / utils / buffer.vim
1 let s:fixendofline_exists = exists('+fixendofline')
2
3 function! s:get_fixendofline(buf) abort
4     let l:eol = getbufvar(a:buf, '&endofline')
5     let l:binary = getbufvar(a:buf, '&binary')
6
7     if s:fixendofline_exists
8         let l:fixeol = getbufvar(a:buf, '&fixendofline')
9
10         if !l:binary
11             " When 'binary' is off and 'fixeol' is on, 'endofline' is not used
12             "
13             " When 'binary' is off and 'fixeol' is off, 'endofline' is used to
14             " remember the presence of a <EOL>
15             return l:fixeol || l:eol
16         else
17             " When 'binary' is on, the value of 'fixeol' doesn't matter
18             return l:eol
19         endif
20     else
21         " When 'binary' is off the value of 'endofline' is not used
22         "
23         " When 'binary' is on 'endofline' is used to remember the presence of
24         " a <EOL>
25         return !l:binary || l:eol
26     endif
27 endfunction
28
29 function! lsp#utils#buffer#_get_fixendofline(bufnr) abort
30     return s:get_fixendofline(a:bufnr)
31 endfunction
32
33 function! lsp#utils#buffer#_get_lines(buf) abort
34     let l:lines = getbufline(a:buf, 1, '$')
35     if s:get_fixendofline(a:buf)
36         let l:lines += ['']
37     endif
38     return l:lines
39 endfunction
40
41 " @params {location} = {
42 "   'uri': 'file://....',
43 "   'range': {
44 "       'start': { 'line': 1, 'character': 1 },
45 "       'end': { 'line': 1, 'character': 1 },
46 "   }
47 " }
48 function! lsp#utils#buffer#_open_lsp_location(location) abort
49     let l:path = lsp#utils#uri_to_path(a:location['uri'])
50     let l:bufnr = bufnr(l:path)
51
52     let [l:start_line, l:start_col] = lsp#utils#position#lsp_to_vim(l:bufnr, a:location['range']['start'])
53     let [l:end_line, l:end_col] = lsp#utils#position#lsp_to_vim(l:bufnr, a:location['range']['end'])
54
55     normal! m'
56     if &modified && !&hidden
57         let l:cmd = l:bufnr !=# -1 ? 'sb ' . l:bufnr : 'split ' . fnameescape(l:path)
58     else
59         let l:cmd = l:bufnr !=# -1 ? 'b ' . l:bufnr : 'edit ' . fnameescape(l:path)
60     endif
61     execute l:cmd . ' | call cursor('.l:start_line.','.l:start_col.')'
62
63     normal! V
64     call setpos("'<", [l:bufnr, l:start_line, l:start_col])
65     call setpos("'>", [l:bufnr, l:end_line, l:end_col])
66 endfunction
67
68 function! lsp#utils#buffer#get_indent_size(bufnr) abort
69     let l:shiftwidth = getbufvar(a:bufnr, '&shiftwidth')
70     if getbufvar(a:bufnr, '&shiftwidth')
71         return l:shiftwidth
72     endif
73     return getbufvar(a:bufnr, '&tabstop')
74 endfunction