let s:save_cpo = &cpoptions
set cpoptions&vim

function! OmniSharp#actions#navigate#Down(...) abort
  if a:0 > 0
    let Callback = a:1
    call s:Navigate(1, Callback)
  else
    call s:Navigate(1)
  endif
endfunction

function! OmniSharp#actions#navigate#Up(...) abort
  if a:0 > 0
    let Callback = a:1
    call s:Navigate(0, Callback)
  else
    call s:Navigate(0)
  endif
endfunction

function! s:Navigate(down, ...) abort
  if g:OmniSharp_server_stdio
    let Callback = a:0 ? a:1 : function('s:NavigateRH')
    let opts = { 'ResponseHandler': Callback }
    call OmniSharp#stdio#Request(a:down ? '/navigatedown' : '/navigateup', opts)
  else
    call OmniSharp#py#Eval(a:down ? 'navigateDown()' : 'navigateUp()')
    call OmniSharp#py#CheckForError()
  endif
endfunction

function! s:NavigateRH(response) abort
  if !a:response.Success | return | endif
  normal! m'
  call cursor(a:response.Body.Line, a:response.Body.Column)
endfunction

let &cpoptions = s:save_cpo
unlet s:save_cpo

" vim:et:sw=2:sts=2

let s:save_cpo = &cpoptions
set cpoptions&vim

" Navigate to the next member definition in the class.
" Optional arguments:
" Callback: When a callback is passed in, it is called after the response is
"           returned with the member location. No navigation is performed when a
"           callback is passed in.
function! OmniSharp#actions#navigate#Down(...) abort
  call s:Navigate(1, a:0 ? a:1 : function('OmniSharp#locations#Navigate'))
endfunction

" See OmniSharp#actions#navigate#Down
function! OmniSharp#actions#navigate#Up(...) abort
  call s:Navigate(0, a:0 ? a:1 : function('OmniSharp#locations#Navigate'))
endfunction

function! s:Navigate(down, Callback) abort
  if g:OmniSharp_server_stdio
    let RH = function('s:StdioNavigateRH', [a:Callback])
    let opts = { 'ResponseHandler': RH }
    call OmniSharp#stdio#Request(a:down ? '/navigatedown' : '/navigateup', opts)
  else
    call OmniSharp#py#Eval(a:down ? 'navigateDown()' : 'navigateUp()')
    call OmniSharp#py#CheckForError()
  endif
endfunction

function! s:StdioNavigateRH(Callback, response) abort
  if !a:response.Success | return | endif
  call a:Callback(OmniSharp#locations#Parse([a:response.Body])[0])
endfunction

let &cpoptions = s:save_cpo
unlet s:save_cpo

" vim:et:sw=2:sts=2

Refactor NavigateUp/Down to use standard locations
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.

OmniSharp/omnisharp-vim,OmniSharp/omnisharp-vim,OmniSharp/omnisharp-vim