diff options
author | Alvin Chan <chaucerbao@users.noreply.github.com> | 2019-01-27 02:18:20 -0800 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2019-01-27 10:18:20 +0000 |
commit | 6288c8b08e360c787e0b41daaf21e06d6da0512a (patch) | |
tree | 30b13dc5be1d9dec962b7eb368c7b845871f77d5 /autoload | |
parent | b8bf7b220d0f7ab461ed830b125f9dbc42a7836a (diff) | |
download | ale-6288c8b08e360c787e0b41daaf21e06d6da0512a.zip |
Use relative paths when previewing file locations (#2238)
* Use relative paths when previewing file locations
Example: ALEFindReferences -relative
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/preview.vim | 11 | ||||
-rw-r--r-- | autoload/ale/references.vim | 32 |
2 files changed, 31 insertions, 12 deletions
diff --git a/autoload/ale/preview.vim b/autoload/ale/preview.vim index 1f50e0ad..5b8fdcdb 100644 --- a/autoload/ale/preview.vim +++ b/autoload/ale/preview.vim @@ -41,16 +41,23 @@ endfunction " Show a location selection preview window, given some items. " Each item should have 'filename', 'line', and 'column' keys. -function! ale#preview#ShowSelection(item_list) abort +function! ale#preview#ShowSelection(item_list, ...) abort + let l:options = get(a:000, 0, {}) + let l:sep = has('win32') ? '\' : '/' let l:lines = [] " Create lines to display to users. for l:item in a:item_list let l:match = get(l:item, 'match', '') + let l:filename = l:item.filename + + if get(l:options, 'use_relative_paths') + let l:filename = substitute(l:item.filename, '^' . getcwd() . l:sep, '', '') " no-custom-checks + endif call add( \ l:lines, - \ l:item.filename + \ l:filename \ . ':' . l:item.line \ . ':' . l:item.column \ . (!empty(l:match) ? ' ' . l:match : ''), diff --git a/autoload/ale/references.vim b/autoload/ale/references.vim index 24267bb4..6d33b443 100644 --- a/autoload/ale/references.vim +++ b/autoload/ale/references.vim @@ -17,7 +17,7 @@ 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) - call remove(s:references_map, a:response.request_seq) + let l:options = remove(s:references_map, a:response.request_seq) if get(a:response, 'success', v:false) is v:true let l:item_list = [] @@ -34,7 +34,7 @@ function! ale#references#HandleTSServerResponse(conn_id, response) abort if empty(l:item_list) call ale#util#Execute('echom ''No references found.''') else - call ale#preview#ShowSelection(l:item_list) + call ale#preview#ShowSelection(l:item_list, l:options) endif endif endif @@ -43,7 +43,7 @@ endfunction function! ale#references#HandleLSPResponse(conn_id, response) abort if has_key(a:response, 'id') \&& has_key(s:references_map, a:response.id) - call remove(s:references_map, a:response.id) + let l:options = remove(s:references_map, a:response.id) " The result can be a Dictionary item, a List of the same, or null. let l:result = get(a:response, 'result', []) @@ -60,12 +60,12 @@ function! ale#references#HandleLSPResponse(conn_id, response) abort if empty(l:item_list) call ale#util#Execute('echom ''No references found.''') else - call ale#preview#ShowSelection(l:item_list) + call ale#preview#ShowSelection(l:item_list, l:options) endif endif endfunction -function! s:OnReady(linter, lsp_details, line, column, ...) abort +function! s:OnReady(linter, lsp_details, line, column, options, ...) abort let l:buffer = a:lsp_details.buffer let l:id = a:lsp_details.connection_id @@ -91,10 +91,12 @@ function! s:OnReady(linter, lsp_details, line, column, ...) abort let l:request_id = ale#lsp#Send(l:id, l:message) - let s:references_map[l:request_id] = {} + let s:references_map[l:request_id] = { + \ 'use_relative_paths': has_key(a:options, 'use_relative_paths') ? a:options.use_relative_paths : 0 + \} endfunction -function! s:FindReferences(linter) abort +function! s:FindReferences(linter, options) abort let l:buffer = bufnr('') let [l:line, l:column] = getcurpos()[1:2] @@ -111,14 +113,24 @@ function! s:FindReferences(linter) abort let l:id = l:lsp_details.connection_id call ale#lsp#WaitForCapability(l:id, 'references', function('s:OnReady', [ - \ a:linter, l:lsp_details, l:line, l:column + \ a:linter, l:lsp_details, l:line, l:column, a:options \])) endfunction -function! ale#references#Find() abort +function! ale#references#Find(...) abort + let l:options = {} + + if len(a:000) > 0 + for l:option in a:000 + if l:option is? '-relative' + let l:options.use_relative_paths = 1 + endif + endfor + endif + for l:linter in ale#linter#Get(&filetype) if !empty(l:linter.lsp) - call s:FindReferences(l:linter) + call s:FindReferences(l:linter, l:options) endif endfor endfunction |