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.
1 function! s:open_location(path, line, col, ...) abort
3 let l:mods = a:0 ? a:1 : ''
4 let l:buffer = bufnr(a:path)
5 if l:mods ==# '' && &modified && !&hidden && l:buffer != bufnr('%')
6 let l:mods = &splitbelow ? 'rightbelow' : 'leftabove'
9 if l:buffer == bufnr('%')
12 let l:cmd = (l:buffer !=# -1 ? 'b ' . l:buffer : 'edit ' . fnameescape(a:path)) . ' | '
15 let l:cmd = l:mods . ' ' . (l:buffer !=# -1 ? 'sb ' . l:buffer : 'split ' . fnameescape(a:path)) . ' | '
17 execute l:cmd . 'call cursor('.a:line.','.a:col.')'
25 function! lsp#utils#location#_open_vim_list_item(location, mods) abort
26 call s:open_location(a:location['filename'], a:location['lnum'], a:location['col'], a:mods)
29 " @params {location} = {
30 " 'uri': 'file://....',
32 " 'start': { 'line': 1, 'character': 1 },
33 " 'end': { 'line': 1, 'character': 1 },
36 function! lsp#utils#location#_open_lsp_location(location) abort
37 let l:path = lsp#utils#uri_to_path(a:location['uri'])
38 let l:bufnr = bufnr(l:path)
40 let [l:start_line, l:start_col] = lsp#utils#position#lsp_to_vim(l:bufnr, a:location['range']['start'])
41 let [l:end_line, l:end_col] = lsp#utils#position#lsp_to_vim(l:bufnr, a:location['range']['end'])
43 call s:open_location(l:path, l:start_line, l:start_col)
46 call setpos("'<", [l:bufnr, l:start_line, l:start_col])
47 call setpos("'>", [l:bufnr, l:end_line, l:end_col])
50 " @param loc = Location | LocationLink
51 " @param cache = {} empty dict
60 function! s:lsp_location_item_to_vim(loc, cache) abort
61 if has_key(a:loc, 'targetUri') " LocationLink
62 let l:uri = a:loc['targetUri']
63 let l:range = a:loc['targetSelectionRange']
66 let l:uri = a:loc['uri']
67 let l:range = a:loc['range']
71 if !lsp#utils#is_file_uri(l:uri)
75 let l:path = lsp#utils#uri_to_path(l:uri)
76 let [l:line, l:col] = lsp#utils#position#lsp_to_vim(l:path, l:range['start'])
78 let l:index = l:line - 1
79 if has_key(a:cache, l:path)
80 let l:text = a:cache[l:path][l:index]
82 let l:contents = getbufline(l:path, 1, '$')
84 let l:text = get(l:contents, l:index, '')
86 let l:contents = readfile(l:path)
87 let a:cache[l:path] = l:contents
88 let l:text = get(l:contents, l:index, '')
93 " viewstart/end decremented to account for incrementing in _lsp_to_vim
99 \ 'viewstart': lsp#utils#position#lsp_to_vim(l:path, a:loc['targetRange']['start'])[0] - 1,
100 \ 'viewend': lsp#utils#position#lsp_to_vim(l:path, a:loc['targetRange']['end'])[0] - 1,
104 \ 'filename': l:path,
112 " @summary Use this to convert loc to vim list that is compatible with
113 " quickfix and locllist items
114 " @param loc = v:null | Location | Location[] | LocationLink
116 function! lsp#utils#location#_lsp_to_vim_list(loc) abort
119 if empty(a:loc) " v:null
121 elseif type(a:loc) == type([]) " Location[]
122 for l:location in a:loc
123 let l:vim_loc = s:lsp_location_item_to_vim(l:location, l:cache)
124 if !empty(l:vim_loc) " https:// uri will return empty
125 call add(l:result, l:vim_loc)
128 else " Location or LocationLink
129 let l:vim_loc = s:lsp_location_item_to_vim(a:loc, l:cache)
130 if !empty(l:vim_loc) " https:// uri will return empty
131 call add(l:result, l:vim_loc)