Skip to content

Commit 655c8f0

Browse files
committed
Refactor NavigateUp/Down to use standard locations
The NavigatUp/NavigateDown functions have, until now, had their own navigation implementation: setting a mark, changing the cursor position. However, as we have standard functions for handling locations, it makes sense to use them, especially with the new optional user callback, as this makes the callback usage more predictable. The callback will now be passed a "location" object (which looks like a quickfix item) with the same structure as the locations returned to GotoDefinition callbacks and FindUsages callbacks etc.
1 parent 0d72875 commit 655c8f0

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

autoload/OmniSharp/actions/navigate.vim

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
let s:save_cpo = &cpoptions
22
set cpoptions&vim
33

4+
" Navigate to the next member definition in the class.
5+
" Optional arguments:
6+
" Callback: When a callback is passed in, it is called after the response is
7+
" returned with the member location. No navigation is performed when a
8+
" callback is passed in.
49
function! OmniSharp#actions#navigate#Down(...) abort
5-
if a:0 > 0
6-
let Callback = a:1
7-
call s:Navigate(1, Callback)
8-
else
9-
call s:Navigate(1)
10-
endif
10+
call s:Navigate(1, a:0 ? a:1 : function('OmniSharp#locations#Navigate'))
1111
endfunction
1212

13+
" See OmniSharp#actions#navigate#Down
1314
function! OmniSharp#actions#navigate#Up(...) abort
14-
if a:0 > 0
15-
let Callback = a:1
16-
call s:Navigate(0, Callback)
17-
else
18-
call s:Navigate(0)
19-
endif
15+
call s:Navigate(0, a:0 ? a:1 : function('OmniSharp#locations#Navigate'))
2016
endfunction
2117

22-
function! s:Navigate(down, ...) abort
18+
function! s:Navigate(down, Callback) abort
2319
if g:OmniSharp_server_stdio
24-
let Callback = a:0 ? a:1 : function('s:NavigateRH')
25-
let opts = { 'ResponseHandler': Callback }
20+
let RH = function('s:StdioNavigateRH', [a:Callback])
21+
let opts = { 'ResponseHandler': RH }
2622
call OmniSharp#stdio#Request(a:down ? '/navigatedown' : '/navigateup', opts)
2723
else
2824
call OmniSharp#py#Eval(a:down ? 'navigateDown()' : 'navigateUp()')
2925
call OmniSharp#py#CheckForError()
3026
endif
3127
endfunction
3228

33-
function! s:NavigateRH(response) abort
29+
function! s:StdioNavigateRH(Callback, response) abort
3430
if !a:response.Success | return | endif
35-
normal! m'
36-
call cursor(a:response.Body.Line, a:response.Body.Column)
31+
call a:Callback(OmniSharp#locations#Parse([a:response.Body])[0])
3732
endfunction
3833

3934
let &cpoptions = s:save_cpo

0 commit comments

Comments
 (0)