@@ -16,9 +16,9 @@ function! OmniSharp#actions#definition#Find(...) abort
16
16
if a: 0 > 1 && type (a: 2 ) == type (function (' tr' ))
17
17
let opts.Callback = a: 2
18
18
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
22
22
if a: 0 > 1 && type (a: 2 ) == type (' ' ) && a: 1 !=# ' '
23
23
let opts.editcommand = a: 2
24
24
endif
@@ -71,7 +71,7 @@ function! s:CBGotoDefinition(opts, location, metadata) abort
71
71
if g: OmniSharp_lookup_metadata
72
72
\ && type (a: metadata ) == type ({})
73
73
\ && 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 )
75
75
let went_to_metadata = 1
76
76
else
77
77
echo ' Not found'
@@ -91,7 +91,7 @@ function! s:CBPreviewDefinition(opts, location, metadata) abort
91
91
if g: OmniSharp_lookup_metadata
92
92
\ && type (a: metadata ) == type ({})
93
93
\ && 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 )
95
95
else
96
96
echo ' Not found'
97
97
endif
@@ -101,6 +101,62 @@ function! s:CBPreviewDefinition(opts, location, metadata) abort
101
101
endif
102
102
endfunction
103
103
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
+
104
160
let &cpoptions = s: save_cpo
105
161
unlet s: save_cpo
106
162
0 commit comments