]> git.madduck.net Git - etc/vim.git/blobdiff - .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:

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / vim-lsp / autoload / lsp / utils / range.vim
diff --git a/.vim/bundle/vim-lsp/autoload/lsp/utils/range.vim b/.vim/bundle/vim-lsp/autoload/lsp/utils/range.vim
new file mode 100644 (file)
index 0000000..3e17632
--- /dev/null
@@ -0,0 +1,82 @@
+"
+" Returns recent visual-mode range.
+"
+function! lsp#utils#range#_get_recent_visual_range() abort
+    let l:start_pos = getpos("'<")[1 : 2]
+    let l:end_pos = getpos("'>")[1 : 2]
+    let l:end_pos[1] += 1 " To exclusive
+
+    " Fix line selection.
+    let l:end_line = getline(l:end_pos[0])
+    if l:end_pos[1] > strlen(l:end_line)
+        let l:end_pos[1] = strlen(l:end_line) + 1
+    endif
+
+    let l:range = {}
+    let l:range['start'] = lsp#utils#position#vim_to_lsp('%', l:start_pos)
+    let l:range['end'] = lsp#utils#position#vim_to_lsp('%', l:end_pos)
+    return l:range
+endfunction
+
+"
+" Returns current line range.
+"
+function! lsp#utils#range#_get_current_line_range() abort
+  let l:pos = getpos('.')[1 : 2]
+  let l:range = {}
+  let l:range['start'] = lsp#utils#position#vim_to_lsp('%', l:pos)
+  let l:range['end'] = lsp#utils#position#vim_to_lsp('%', [l:pos[0], l:pos[1] + strlen(getline(l:pos[0])) + 1])
+  return l:range
+endfunction
+
+" Convert a LSP range to one or more vim match positions.
+" If the range spans over multiple lines, break it down to multiple
+" positions, one for each line.
+" Return a list of positions.
+function! lsp#utils#range#lsp_to_vim(bufnr, range) abort
+    let l:position = []
+
+    let [l:start_line, l:start_col] = lsp#utils#position#lsp_to_vim(a:bufnr, a:range['start'])
+    let [l:end_line, l:end_col] = lsp#utils#position#lsp_to_vim(a:bufnr, a:range['end'])
+    if l:end_line == l:start_line
+        let l:position = [[
+        \ l:start_line,
+        \ l:start_col,
+        \ l:end_col - l:start_col
+        \ ]]
+    else
+        " First line
+        let l:position = [[
+        \ l:start_line,
+        \ l:start_col,
+        \ 999
+        \ ]]
+
+        " Last line
+        call add(l:position, [
+        \ l:end_line,
+        \ 1,
+        \ l:end_col
+        \ ])
+
+        " Lines in the middle
+        let l:middle_lines = map(
+        \ range(l:start_line + 1, l:end_line - 1),
+        \ {_, l -> [l, 0, 999]}
+        \ )
+
+        call extend(l:position, l:middle_lines)
+    endif
+
+    return l:position
+endfunction
+
+function! lsp#utils#range#get_range() abort
+    let l:char = lsp#utils#to_char('%', line('$'), col('$'))
+    return {'start': {'line': 0, 'character': 0}, 'end': {'line': line('$')-1, 'character': l:char}}
+endfunction
+
+function! lsp#utils#range#get_range_curline() abort
+    let l:char = lsp#utils#to_char('%', line('.'), col('$'))
+    return {'start': {'line': line('.')-1, 'character': 0}, 'end': {'line': line('.')-1, 'character': l:char}}
+endfunction