mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 04:34:25 +08:00
Implement listing all returned results for LSP textDocument/implements (#4755)
* Fix list of definitions * Fix when LSP returns single response on definition/implementation * Update tag stack on ShowSelection
This commit is contained in:
@@ -35,22 +35,94 @@ function! ale#definition#UpdateTagStack() abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ale#definition#FormatTSServerResponse(response_item, options) abort
|
||||||
|
if get(a:options, 'open_in') is# 'quickfix'
|
||||||
|
return {
|
||||||
|
\ 'filename': a:response_item.file,
|
||||||
|
\ 'lnum': a:response_item.start.line,
|
||||||
|
\ 'col': a:response_item.start.offset,
|
||||||
|
\}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
\ 'filename': a:response_item.file,
|
||||||
|
\ 'line': a:response_item.start.line,
|
||||||
|
\ 'column': a:response_item.start.offset,
|
||||||
|
\}
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale#definition#HandleTSServerResponse(conn_id, response) abort
|
function! ale#definition#HandleTSServerResponse(conn_id, response) abort
|
||||||
if has_key(a:response, 'request_seq')
|
if has_key(a:response, 'request_seq')
|
||||||
\&& has_key(s:go_to_definition_map, a:response.request_seq)
|
\&& has_key(s:go_to_definition_map, a:response.request_seq)
|
||||||
let l:options = remove(s:go_to_definition_map, a:response.request_seq)
|
let l:options = remove(s:go_to_definition_map, a:response.request_seq)
|
||||||
|
|
||||||
if get(a:response, 'success', v:false) is v:true && !empty(a:response.body)
|
if get(a:response, 'success', v:false) is v:true && !empty(a:response.body)
|
||||||
let l:filename = a:response.body[0].file
|
let l:item_list = []
|
||||||
let l:line = a:response.body[0].start.line
|
|
||||||
let l:column = a:response.body[0].start.offset
|
|
||||||
|
|
||||||
call ale#definition#UpdateTagStack()
|
for l:response_item in a:response.body
|
||||||
call ale#util#Open(l:filename, l:line, l:column, l:options)
|
call add(
|
||||||
|
\ l:item_list,
|
||||||
|
\ ale#definition#FormatTSServerResponse(l:response_item, l:options)
|
||||||
|
\)
|
||||||
|
endfor
|
||||||
|
|
||||||
|
if empty(l:item_list)
|
||||||
|
call ale#util#Execute('echom ''No definitions found''')
|
||||||
|
elseif len(l:item_list) == 1
|
||||||
|
let l:filename = l:item_list[0].filename
|
||||||
|
|
||||||
|
if get(l:options, 'open_in') is# 'quickfix'
|
||||||
|
let l:line = l:item_list[0].lnum
|
||||||
|
let l:column = l:item_list[0].col
|
||||||
|
else
|
||||||
|
let l:line = l:item_list[0].line
|
||||||
|
let l:column = l:item_list[0].column
|
||||||
|
endif
|
||||||
|
|
||||||
|
call ale#definition#UpdateTagStack()
|
||||||
|
call ale#util#Open(l:filename, l:line, l:column, l:options)
|
||||||
|
else
|
||||||
|
if get(l:options, 'open_in') is# 'quickfix'
|
||||||
|
call setqflist([], 'r')
|
||||||
|
call setqflist(l:item_list, 'a')
|
||||||
|
call ale#util#Execute('cc 1')
|
||||||
|
else
|
||||||
|
call ale#definition#UpdateTagStack()
|
||||||
|
call ale#preview#ShowSelection(l:item_list, l:options)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ale#definition#FormatLSPResponse(response_item, options) abort
|
||||||
|
if has_key(a:response_item, 'targetUri')
|
||||||
|
" LocationLink items use targetUri
|
||||||
|
let l:uri = a:response_item.targetUri
|
||||||
|
let l:line = a:response_item.targetRange.start.line + 1
|
||||||
|
let l:column = a:response_item.targetRange.start.character + 1
|
||||||
|
else
|
||||||
|
" LocationLink items use uri
|
||||||
|
let l:uri = a:response_item.uri
|
||||||
|
let l:line = a:response_item.range.start.line + 1
|
||||||
|
let l:column = a:response_item.range.start.character + 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if get(a:options, 'open_in') is# 'quickfix'
|
||||||
|
return {
|
||||||
|
\ 'filename': ale#util#ToResource(l:uri),
|
||||||
|
\ 'lnum': l:line,
|
||||||
|
\ 'col': l:column,
|
||||||
|
\}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
\ 'filename': ale#util#ToResource(l:uri),
|
||||||
|
\ 'line': l:line,
|
||||||
|
\ 'column': l:column,
|
||||||
|
\}
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale#definition#HandleLSPResponse(conn_id, response) abort
|
function! ale#definition#HandleLSPResponse(conn_id, response) abort
|
||||||
if has_key(a:response, 'id')
|
if has_key(a:response, 'id')
|
||||||
\&& has_key(s:go_to_definition_map, a:response.id)
|
\&& has_key(s:go_to_definition_map, a:response.id)
|
||||||
@@ -65,21 +137,29 @@ function! ale#definition#HandleLSPResponse(conn_id, response) abort
|
|||||||
let l:result = []
|
let l:result = []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
for l:item in l:result
|
let l:item_list = []
|
||||||
if has_key(l:item, 'targetUri')
|
|
||||||
" LocationLink items use targetUri
|
|
||||||
let l:uri = l:item.targetUri
|
|
||||||
let l:line = l:item.targetRange.start.line + 1
|
|
||||||
let l:column = l:item.targetRange.start.character + 1
|
|
||||||
else
|
|
||||||
" LocationLink items use uri
|
|
||||||
let l:uri = l:item.uri
|
|
||||||
let l:line = l:item.range.start.line + 1
|
|
||||||
let l:column = l:item.range.start.character + 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
for l:response_item in l:result
|
||||||
|
call add(l:item_list,
|
||||||
|
\ ale#definition#FormatLSPResponse(l:response_item, l:options)
|
||||||
|
\)
|
||||||
|
endfor
|
||||||
|
|
||||||
|
if empty(l:item_list)
|
||||||
|
call ale#util#Execute('echom ''No definitions found''')
|
||||||
|
elseif len(l:item_list) == 1
|
||||||
call ale#definition#UpdateTagStack()
|
call ale#definition#UpdateTagStack()
|
||||||
|
|
||||||
|
let l:uri = ale#util#ToURI(l:item_list[0].filename)
|
||||||
|
|
||||||
|
if get(l:options, 'open_in') is# 'quickfix'
|
||||||
|
let l:line = l:item_list[0].lnum
|
||||||
|
let l:column = l:item_list[0].col
|
||||||
|
else
|
||||||
|
let l:line = l:item_list[0].line
|
||||||
|
let l:column = l:item_list[0].column
|
||||||
|
endif
|
||||||
|
|
||||||
let l:uri_handler = ale#uri#GetURIHandler(l:uri)
|
let l:uri_handler = ale#uri#GetURIHandler(l:uri)
|
||||||
|
|
||||||
if l:uri_handler is# v:null
|
if l:uri_handler is# v:null
|
||||||
@@ -88,9 +168,16 @@ function! ale#definition#HandleLSPResponse(conn_id, response) abort
|
|||||||
else
|
else
|
||||||
call l:uri_handler.OpenURILink(l:uri, l:line, l:column, l:options, a:conn_id)
|
call l:uri_handler.OpenURILink(l:uri, l:line, l:column, l:options, a:conn_id)
|
||||||
endif
|
endif
|
||||||
|
else
|
||||||
break
|
if get(l:options, 'open_in') is# 'quickfix'
|
||||||
endfor
|
call setqflist([], 'r')
|
||||||
|
call setqflist(l:item_list, 'a')
|
||||||
|
call ale#util#Execute('cc 1')
|
||||||
|
else
|
||||||
|
call ale#definition#UpdateTagStack()
|
||||||
|
call ale#preview#ShowSelection(l:item_list, l:options)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -458,19 +458,15 @@ Execute(Definition responses with lists should be handled):
|
|||||||
\ }
|
\ }
|
||||||
\)
|
\)
|
||||||
|
|
||||||
AssertEqual
|
" Multiple results should either open the ALEPreview or go to quickfix
|
||||||
\ [
|
AssertEqual [1, 1], getpos('.')[1:2]
|
||||||
\ 'edit +3 ' . fnameescape(ale#path#Simplify(g:dir . '/completion_dummy_file')),
|
|
||||||
\ ],
|
|
||||||
\ g:expr_list
|
|
||||||
AssertEqual [3, 8], getpos('.')[1:2]
|
|
||||||
AssertEqual {}, ale#definition#GetMap()
|
AssertEqual {}, ale#definition#GetMap()
|
||||||
|
|
||||||
Execute(Definition responses with null response should be handled):
|
Execute(Definition responses with null response should be handled):
|
||||||
call ale#definition#SetMap({3: {'open_in': 'current-buffer'}})
|
call ale#definition#SetMap({3: {'open_in': 'current-buffer'}})
|
||||||
call ale#definition#HandleLSPResponse(1, {'id': 3, 'result': v:null})
|
call ale#definition#HandleLSPResponse(1, {'id': 3, 'result': v:null})
|
||||||
|
|
||||||
AssertEqual [], g:expr_list
|
AssertEqual ['echom ''No definitions found'''], g:expr_list
|
||||||
|
|
||||||
Execute(LSP definition requests should be sent):
|
Execute(LSP definition requests should be sent):
|
||||||
runtime ale_linters/python/pylsp.vim
|
runtime ale_linters/python/pylsp.vim
|
||||||
|
|||||||
Reference in New Issue
Block a user