Skip to content

Commit 4d6b87f

Browse files
committed
Add optional callback to FindSymbol/FindType
1 parent 3c98990 commit 4d6b87f

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

autoload/OmniSharp/actions/symbols.vim

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
11
let s:save_cpo = &cpoptions
22
set cpoptions&vim
33

4+
" Find all project symbols, or all symbols including a search substring. Symbol
5+
" locations are loaded in the configured selector, :help g:OmniSharp_selector_ui
6+
" Optional arguments:
7+
" symbolName: Partial name of the symbol to search for.
8+
" Callback: When a callback is passed in, it is called after the response is
9+
" returned (synchronously or asynchronously) with the found symbol
10+
" locations.
411
function! OmniSharp#actions#symbols#Find(...) abort
5-
let filter = a:0 && a:1 isnot 0 ? a:1 : ''
6-
let symbolfilter = a:0 == 2 ? a:2 : 'TypeAndMember'
12+
if a:0 && type(a:1) == type('')
13+
let filter = a:1
14+
elseif a:0 > 1 && type(a:2) == type('')
15+
let filter = a:2
16+
else
17+
let filter = ''
18+
endif
19+
if a:0 && type(a:1) == type(function('tr'))
20+
let Callback = a:1
21+
elseif a:0 > 1 && type(a:2) == type(function('tr'))
22+
let Callback = a:2
23+
else
24+
let Callback = function('s:CBFindSymbol', [filter])
25+
endif
26+
call s:Find(filter, 'TypeAndMember', Callback)
27+
endfunction
28+
29+
" Find all project types. This function is similar to
30+
" OmniSharp#actions#symbols#Find() but returns fewer results, and can be
31+
" significanltly faster in a large codebase.
32+
function! OmniSharp#actions#symbols#FindType(...) abort
33+
if a:0 && type(a:1) == type('')
34+
let filter = a:1
35+
elseif a:0 > 1 && type(a:2) == type('')
36+
let filter = a:2
37+
else
38+
let filter = ''
39+
endif
40+
if a:0 && type(a:1) == type(function('tr'))
41+
let Callback = a:1
42+
elseif a:0 > 1 && type(a:2) == type(function('tr'))
43+
let Callback = a:2
44+
else
45+
let Callback = function('s:CBFindSymbol', [filter])
46+
endif
47+
call s:Find(filter, 'Type', Callback)
48+
endfunction
49+
50+
function! s:Find(filter, symbolfilter, Callback) abort
751
if !OmniSharp#IsServerRunning() | return | endif
852
if g:OmniSharp_server_stdio
9-
let Callback = function('s:CBFindSymbol', [filter])
10-
call s:StdioFind(filter, symbolfilter, Callback)
53+
call s:StdioFind(a:filter, a:symbolfilter, a:Callback)
1154
else
12-
let locs = OmniSharp#py#Eval(printf('findSymbols(%s, %s)', string(filter), string(symbolfilter)))
55+
let locs = OmniSharp#py#Eval(printf('findSymbols(%s, %s)', string(a:filter), string(a:symbolfilter)))
1356
if OmniSharp#py#CheckForError() | return | endif
14-
return s:CBFindSymbol(filter, locs)
57+
return a:Callback(locs)
1558
endif
1659
endfunction
1760

ftplugin/cs/OmniSharp.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ command! -buffer -bar OmniSharpDocumentation call OmniSharp#actions#documentatio
3131
command! -buffer -bar OmniSharpFindImplementations call OmniSharp#actions#implementations#Find()
3232
command! -buffer -bar OmniSharpFindMembers call OmniSharp#actions#members#Find()
3333
command! -buffer -bar -nargs=? OmniSharpFindSymbol call OmniSharp#actions#symbols#Find(<q-args>)
34-
command! -buffer -bar -nargs=? OmniSharpFindType call OmniSharp#actions#symbols#Find(<q-args>, 'Type')
34+
command! -buffer -bar -nargs=? OmniSharpFindType call OmniSharp#actions#symbols#FindType(<q-args>)
3535
command! -buffer -bar OmniSharpFindUsages call OmniSharp#actions#usages#Find()
3636
command! -buffer -bar OmniSharpFixUsings call OmniSharp#actions#usings#Fix()
3737
command! -buffer -bar OmniSharpGetCodeActions call OmniSharp#actions#codeactions#Get('normal')

0 commit comments

Comments
 (0)