]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/vim-lsp/autoload/lsp/utils/range.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:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / vim-lsp / autoload / lsp / utils / range.vim
1 "
2 " Returns recent visual-mode range.
3 "
4 function! lsp#utils#range#_get_recent_visual_range() abort
5     let l:start_pos = getpos("'<")[1 : 2]
6     let l:end_pos = getpos("'>")[1 : 2]
7     let l:end_pos[1] += 1 " To exclusive
8
9     " Fix line selection.
10     let l:end_line = getline(l:end_pos[0])
11     if l:end_pos[1] > strlen(l:end_line)
12         let l:end_pos[1] = strlen(l:end_line) + 1
13     endif
14
15     let l:range = {}
16     let l:range['start'] = lsp#utils#position#vim_to_lsp('%', l:start_pos)
17     let l:range['end'] = lsp#utils#position#vim_to_lsp('%', l:end_pos)
18     return l:range
19 endfunction
20
21 "
22 " Returns current line range.
23 "
24 function! lsp#utils#range#_get_current_line_range() abort
25   let l:pos = getpos('.')[1 : 2]
26   let l:range = {}
27   let l:range['start'] = lsp#utils#position#vim_to_lsp('%', l:pos)
28   let l:range['end'] = lsp#utils#position#vim_to_lsp('%', [l:pos[0], l:pos[1] + strlen(getline(l:pos[0])) + 1])
29   return l:range
30 endfunction
31
32 " Convert a LSP range to one or more vim match positions.
33 " If the range spans over multiple lines, break it down to multiple
34 " positions, one for each line.
35 " Return a list of positions.
36 function! lsp#utils#range#lsp_to_vim(bufnr, range) abort
37     let l:position = []
38
39     let [l:start_line, l:start_col] = lsp#utils#position#lsp_to_vim(a:bufnr, a:range['start'])
40     let [l:end_line, l:end_col] = lsp#utils#position#lsp_to_vim(a:bufnr, a:range['end'])
41     if l:end_line == l:start_line
42         let l:position = [[
43         \ l:start_line,
44         \ l:start_col,
45         \ l:end_col - l:start_col
46         \ ]]
47     else
48         " First line
49         let l:position = [[
50         \ l:start_line,
51         \ l:start_col,
52         \ 999
53         \ ]]
54
55         " Last line
56         call add(l:position, [
57         \ l:end_line,
58         \ 1,
59         \ l:end_col
60         \ ])
61
62         " Lines in the middle
63         let l:middle_lines = map(
64         \ range(l:start_line + 1, l:end_line - 1),
65         \ {_, l -> [l, 0, 999]}
66         \ )
67
68         call extend(l:position, l:middle_lines)
69     endif
70
71     return l:position
72 endfunction
73
74 function! lsp#utils#range#get_range() abort
75     let l:char = lsp#utils#to_char('%', line('$'), col('$'))
76     return {'start': {'line': 0, 'character': 0}, 'end': {'line': line('$')-1, 'character': l:char}}
77 endfunction
78
79 function! lsp#utils#range#get_range_curline() abort
80     let l:char = lsp#utils#to_char('%', line('.'), col('$'))
81     return {'start': {'line': line('.')-1, 'character': 0}, 'end': {'line': line('.')-1, 'character': l:char}}
82 endfunction