mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-06 18:07:46 +08:00
add preview for ALEFindReferences (#5001)
* add preview for ALEFindReferences * ALEFindReferences: add -contents options and g:ale_references_show_contents option to configure default behaviour * tests: add tests for ALEFindReferences -contents feature * tests: update tsserver references tests with show_contents args
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
let g:ale_default_navigation = get(g:, 'ale_default_navigation', 'buffer')
|
||||
let g:ale_references_show_contents = get(g:, 'ale_references_show_contents', 1)
|
||||
|
||||
let s:references_map = {}
|
||||
|
||||
@@ -67,17 +68,33 @@ function! ale#references#HandleTSServerResponse(conn_id, response) abort
|
||||
endfunction
|
||||
|
||||
function! ale#references#FormatLSPResponseItem(response_item, options) abort
|
||||
let l:line_text = ''
|
||||
|
||||
let l:line= a:response_item.range.start.line
|
||||
let l:col = a:response_item.range.start.character
|
||||
let l:filename = ale#util#ToResource(a:response_item.uri)
|
||||
|
||||
if get(a:options, 'show_contents') == 1
|
||||
try
|
||||
let l:line_text = substitute(readfile(l:filename)[l:line], '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
catch
|
||||
" This happens in tests
|
||||
endtry
|
||||
endif
|
||||
|
||||
if get(a:options, 'open_in') is# 'quickfix'
|
||||
return {
|
||||
\ 'filename': ale#util#ToResource(a:response_item.uri),
|
||||
\ 'filename': l:filename,
|
||||
\ 'lnum': a:response_item.range.start.line + 1,
|
||||
\ 'col': a:response_item.range.start.character + 1,
|
||||
\ 'text': l:line_text,
|
||||
\}
|
||||
else
|
||||
return {
|
||||
\ 'filename': ale#util#ToResource(a:response_item.uri),
|
||||
\ 'line': a:response_item.range.start.line + 1,
|
||||
\ 'column': a:response_item.range.start.character + 1,
|
||||
\ 'filename': l:filename,
|
||||
\ 'line': l:line + 1,
|
||||
\ 'column': l:col + 1,
|
||||
\ 'match': l:line_text,
|
||||
\}
|
||||
endif
|
||||
endfunction
|
||||
@@ -147,6 +164,7 @@ function! s:OnReady(line, column, options, linter, lsp_details) abort
|
||||
let s:references_map[l:request_id] = {
|
||||
\ 'use_relative_paths': has_key(a:options, 'use_relative_paths') ? a:options.use_relative_paths : 0,
|
||||
\ 'open_in': get(a:options, 'open_in', 'current-buffer'),
|
||||
\ 'show_contents': a:options.show_contents,
|
||||
\}
|
||||
endfunction
|
||||
|
||||
@@ -165,6 +183,8 @@ function! ale#references#Find(...) abort
|
||||
let l:options.open_in = 'vsplit'
|
||||
elseif l:option is? '-quickfix'
|
||||
let l:options.open_in = 'quickfix'
|
||||
elseif l:option is? '-contents'
|
||||
let l:options.show_contents = 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
@@ -177,6 +197,10 @@ function! ale#references#Find(...) abort
|
||||
endif
|
||||
endif
|
||||
|
||||
if !has_key(l:options, 'show_contents')
|
||||
let l:options.show_contents = ale#Var(bufnr(''), 'references_show_contents')
|
||||
endif
|
||||
|
||||
let l:buffer = bufnr('')
|
||||
let [l:line, l:column] = getpos('.')[1:2]
|
||||
let l:column = min([l:column, len(getline(l:line))])
|
||||
|
||||
Reference in New Issue
Block a user