@@ -16,9 +16,9 @@ function! OmniSharp#actions#definition#Find(...) abort
1616 if a: 0 > 1 && type (a: 2 ) == type (function (' tr' ))
1717 let opts.Callback = a: 2
1818 endif
19- if a: 0 && type (a: 1 ) == type (' ' ) && a: 1 !=# ' '
20- let opts.editcommand = a: 1
21- endif
19+ if a: 0 && type (a: 1 ) == type (' ' ) && a: 1 !=# ' '
20+ let opts.editcommand = a: 1
21+ endif
2222 if a: 0 > 1 && type (a: 2 ) == type (' ' ) && a: 1 !=# ' '
2323 let opts.editcommand = a: 2
2424 endif
@@ -71,7 +71,7 @@ function! s:CBGotoDefinition(opts, location, metadata) abort
7171 if g: OmniSharp_lookup_metadata
7272 \ && type (a: metadata ) == type ({})
7373 \ && type (a: metadata .MetadataSource) == type ({})
74- let found = OmniSharp#actions#metadata#Find (0 , a: metadata , a: opts )
74+ let found = s: MetadataFind (0 , a: metadata , a: opts )
7575 let went_to_metadata = 1
7676 else
7777 echo ' Not found'
@@ -91,7 +91,7 @@ function! s:CBPreviewDefinition(opts, location, metadata) abort
9191 if g: OmniSharp_lookup_metadata
9292 \ && type (a: metadata ) == type ({})
9393 \ && type (a: metadata .MetadataSource) == type ({})
94- let found = OmniSharp#actions#metadata#Find (1 , a: metadata , a: opts )
94+ let found = s: MetadataFind (1 , a: metadata , a: opts )
9595 else
9696 echo ' Not found'
9797 endif
@@ -101,6 +101,62 @@ function! s:CBPreviewDefinition(opts, location, metadata) abort
101101 endif
102102endfunction
103103
104+ function ! s: MetadataFind (open_in_preview, metadata, opts) abort
105+ if g: OmniSharp_server_stdio
106+ let Callback = function (' s:CBGotoMetadata' , [a: open_in_preview , a: opts ])
107+ call s: StdioMetadataFind (Callback, a: metadata )
108+ return 1
109+ else
110+ echomsg ' GotoMetadata is not supported with the HTTP OmniSharp server. '
111+ \ . ' Please consider upgrading to the stdio version.'
112+ return 0
113+ endif
114+ endfunction
115+
116+ function ! s: StdioMetadataFind (Callback, metadata) abort
117+ let opts = {
118+ \ ' ResponseHandler' : function (' s:StdioMetadataFindRH' , [a: Callback , a: metadata ]),
119+ \ ' Parameters' : a: metadata .MetadataSource
120+ \}
121+ call OmniSharp#stdio#Request (' /metadata' , opts)
122+ endfunction
123+
124+ function ! s: StdioMetadataFindRH (Callback, metadata, response) abort
125+ if ! a: response .Success || a: response .Body.Source == v: null | return 0 | endif
126+ call a: Callback (a: response .Body, a: metadata )
127+ endfunction
128+
129+ function ! s: CBGotoMetadata (open_in_preview, opts, response, metadata) abort
130+ let host = OmniSharp#GetHost ()
131+ let metadata_filename = fnamemodify (
132+ \ OmniSharp#util#TranslatePathForClient (a: response .SourceName), ' :t' )
133+ let temp_file = OmniSharp#util#TempDir () . ' /' . metadata_filename
134+ let lines = split (a: response .Source , " \n " , 1 )
135+ let lines = map (lines , {i ,v - > substitute (v , ' \r' , ' ' , ' g' )})
136+ call writefile (lines , temp_file, ' b' )
137+ let bufnr = bufadd (temp_file)
138+ call setbufvar (bufnr , ' OmniSharp_host' , host)
139+ call setbufvar (bufnr , ' OmniSharp_metadata_filename' , a: response .SourceName)
140+ let jumped_from_preview = &previewwindow
141+ let location = {
142+ \ ' filename' : temp_file,
143+ \ ' lnum' : a: metadata .Line,
144+ \ ' col' : a: metadata .Column
145+ \}
146+ if a: open_in_preview
147+ call OmniSharp#locations#Preview (location)
148+ else
149+ call OmniSharp#locations#Navigate (location, get (a: opts , ' editcommand' , ' edit' ))
150+ setlocal nomodifiable readonly
151+ endif
152+ if a: open_in_preview && ! jumped_from_preview && &previewwindow
153+ silent wincmd p
154+ endif
155+ if has_key (a: opts , ' Callback' )
156+ call a: opts .Callback (1 ) " found
157+ endif
158+ endfunction
159+
104160let &cpoptions = s: save_cpo
105161unlet s: save_cpo
106162
0 commit comments