summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorDalius Dobravolskas <daliusd@wix.com>2022-02-05 14:54:26 +0200
committerGitHub <noreply@github.com>2022-02-05 21:54:26 +0900
commit0c276aac90f5a49fcf2609d348a11ee0608dd558 (patch)
tree387ed5594a7d7755bfcfb87700575865ab6cea28 /autoload
parenta58b7b5efb058ca8ba597289af2ab49ee56bfc46 (diff)
downloadale-0c276aac90f5a49fcf2609d348a11ee0608dd558.zip
Allows to use quickfix for references. (#4033)
* Allows to use quickfix for references. E.g. following mapping could be used to find references for item under cursor and put result into quickfix list: ``` nnoremap <leader>af :ALEFindReferences -quickfix<CR> ``` Fixes #1759 * Documentation update.
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/references.vim69
1 files changed, 56 insertions, 13 deletions
diff --git a/autoload/ale/references.vim b/autoload/ale/references.vim
index 38ff0d3d..be2254e2 100644
--- a/autoload/ale/references.vim
+++ b/autoload/ale/references.vim
@@ -16,6 +16,23 @@ function! ale#references#ClearLSPData() abort
let s:references_map = {}
endfunction
+function! ale#references#FormatTSResponseItem(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,
+ \ 'match': substitute(a:response_item.lineText, '^\s*\(.\{-}\)\s*$', '\1', ''),
+ \}
+ endif
+endfunction
+
function! ale#references#HandleTSServerResponse(conn_id, response) abort
if get(a:response, 'command', '') is# 'references'
\&& has_key(s:references_map, a:response.request_seq)
@@ -25,23 +42,43 @@ function! ale#references#HandleTSServerResponse(conn_id, response) abort
let l:item_list = []
for l:response_item in a:response.body.refs
- call add(l:item_list, {
- \ 'filename': l:response_item.file,
- \ 'line': l:response_item.start.line,
- \ 'column': l:response_item.start.offset,
- \ 'match': substitute(l:response_item.lineText, '^\s*\(.\{-}\)\s*$', '\1', ''),
- \})
+ call add(
+ \ l:item_list,
+ \ ale#references#FormatTSResponseItem(l:response_item, l:options)
+ \)
endfor
if empty(l:item_list)
call ale#util#Execute('echom ''No references found.''')
else
- call ale#preview#ShowSelection(l:item_list, l:options)
+ 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#preview#ShowSelection(l:item_list, l:options)
+ endif
endif
endif
endif
endfunction
+function! ale#references#FormatLSPResponseItem(response_item, options) abort
+ if get(a:options, 'open_in') is# 'quickfix'
+ return {
+ \ 'filename': ale#path#FromURI(a:response_item.uri),
+ \ 'lnum': a:response_item.range.start.line + 1,
+ \ 'col': a:response_item.range.start.character + 1,
+ \}
+ else
+ return {
+ \ 'filename': ale#path#FromURI(a:response_item.uri),
+ \ 'line': a:response_item.range.start.line + 1,
+ \ 'column': a:response_item.range.start.character + 1,
+ \}
+ endif
+endfunction
+
function! ale#references#HandleLSPResponse(conn_id, response) abort
if has_key(a:response, 'id')
\&& has_key(s:references_map, a:response.id)
@@ -53,18 +90,22 @@ function! ale#references#HandleLSPResponse(conn_id, response) abort
if type(l:result) is v:t_list
for l:response_item in l:result
- call add(l:item_list, {
- \ 'filename': ale#path#FromURI(l:response_item.uri),
- \ 'line': l:response_item.range.start.line + 1,
- \ 'column': l:response_item.range.start.character + 1,
- \})
+ call add(l:item_list,
+ \ ale#references#FormatLSPResponseItem(l:response_item, l:options)
+ \)
endfor
endif
if empty(l:item_list)
call ale#util#Execute('echom ''No references found.''')
else
- call ale#preview#ShowSelection(l:item_list, l:options)
+ 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#preview#ShowSelection(l:item_list, l:options)
+ endif
endif
endif
endfunction
@@ -119,6 +160,8 @@ function! ale#references#Find(...) abort
let l:options.open_in = 'split'
elseif l:option is? '-vsplit'
let l:options.open_in = 'vsplit'
+ elseif l:option is? '-quickfix'
+ let l:options.open_in = 'quickfix'
endif
endfor
endif