Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -relative option to ALESymbolSearch #2255

Merged
merged 5 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions autoload/ale/symbol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ function! ale#symbol#HandleLSPResponse(conn_id, response) abort
if empty(l:item_list)
call ale#util#Execute('echom ''No symbols 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, query, ...) abort
function! s:OnReady(linter, lsp_details, query, options, ...) abort
let l:buffer = a:lsp_details.buffer

" If we already made a request, stop here.
Expand All @@ -76,34 +76,42 @@ function! s:OnReady(linter, lsp_details, query, ...) abort
call setbufvar(l:buffer, 'ale_symbol_request_made', 1)
let s:symbol_map[l:request_id] = {
\ 'buffer': l:buffer,
\ 'use_relative_paths': has_key(a:options, 'use_relative_paths') ? a:options.use_relative_paths : 0
\}
endfunction

function! s:Search(linter, buffer, query) abort
function! s:Search(linter, buffer, query, options) abort
let l:lsp_details = ale#lsp_linter#StartLSP(a:buffer, a:linter)

if !empty(l:lsp_details)
call ale#lsp#WaitForCapability(
\ l:lsp_details.connection_id,
\ 'symbol_search',
\ function('s:OnReady', [a:linter, l:lsp_details, a:query]),
\ function('s:OnReady', [a:linter, l:lsp_details, a:query, a:options]),
\)
endif
endfunction

function! ale#symbol#Search(query) abort
if type(a:query) isnot v:t_string || empty(a:query)
function! ale#symbol#Search(args) abort
let [l:opts, l:query] = ale#args#Parse(['relative'], a:args)

if empty(l:query)
throw 'A non-empty string must be provided!'
endif

let l:buffer = bufnr('')
let l:options = {}

if has_key(l:opts, 'relative')
let l:options.use_relative_paths = 1
endif

" Set a flag so we only make one request.
call setbufvar(l:buffer, 'ale_symbol_request_made', 0)

for l:linter in ale#linter#Get(getbufvar(l:buffer, '&filetype'))
if !empty(l:linter.lsp) && l:linter.lsp isnot# 'tsserver'
call s:Search(l:linter, l:buffer, a:query)
call s:Search(l:linter, l:buffer, l:query, l:options)
endif
endfor
endfunction
4 changes: 4 additions & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ supported:

|ALEFindReferences| - Find references for the word under the cursor.

Options:
`-relative` Show file paths in the results relative to the working dir

-------------------------------------------------------------------------------
5.5 Hovering *ale-hover*
Expand Down Expand Up @@ -931,6 +933,8 @@ commands are supported:

|ALESymbolSearch| - Search for symbols in the workspace.

Options:
`-relative` Show file paths in the results relative to the working dir

===============================================================================
6. Global Options *ale-options*
Expand Down
18 changes: 16 additions & 2 deletions test/test_symbol_search.vader
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Before:
let g:message_list = []
let g:preview_called = 0
let g:item_list = []
let g:options = {}
let g:capability_checked = ''
let g:conn_id = v:null
let g:WaitCallback = v:null
Expand Down Expand Up @@ -47,9 +48,10 @@ Before:
call add(g:expr_list, a:expr)
endfunction

function! ale#preview#ShowSelection(item_list) abort
function! ale#preview#ShowSelection(item_list, options) abort
let g:preview_called = 1
let g:item_list = a:item_list
let g:options = a:options
endfunction

After:
Expand All @@ -63,6 +65,7 @@ After:
unlet! g:message_list
unlet! g:expr_list
unlet! b:ale_linters
unlet! g:options
unlet! g:item_list
unlet! g:preview_called

Expand Down Expand Up @@ -170,4 +173,15 @@ Execute(LSP symbol requests should be sent):
\ ],
\ g:message_list

AssertEqual {'42': {'buffer': bufnr('')}}, ale#symbol#GetMap()
AssertEqual {'42': {'buffer': bufnr(''), 'use_relative_paths': 0}}, ale#symbol#GetMap()

Execute('-relative' argument should enable 'use_relative_paths' in HandleLSPResponse):
runtime ale_linters/python/pyls.vim
let b:ale_linters = ['pyls']
call setpos('.', [bufnr(''), 1, 5, 0])

ALESymbolSearch -relative foo bar

call call(g:WaitCallback, [g:conn_id, '/foo/bar'])

AssertEqual {'42': {'buffer': bufnr(''), 'use_relative_paths': 1}}, ale#symbol#GetMap()