@@ -92,29 +92,26 @@ export function registerRazorEndpoints(
9292 const documentManager = new HtmlDocumentManager ( platformInfo , razorLogger ) ;
9393 context . subscriptions . push ( documentManager . register ( ) ) ;
9494
95- registerRequestHandler < HtmlUpdateParameters , void > ( 'razor/updateHtml' , async ( params ) => {
95+ registerMethodHandler < HtmlUpdateParameters , void > ( 'razor/updateHtml' , async ( params ) => {
9696 const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
9797 await documentManager . updateDocumentText ( uri , params . text ) ;
9898 } ) ;
9999
100- registerRequestHandler < DocumentColorParams , ColorInformation [ ] > ( DocumentColorRequest . method , async ( params ) => {
100+ registerRequestHandler ( DocumentColorRequest . type , async ( params ) => {
101101 const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
102102 const document = await documentManager . getDocument ( uri ) ;
103103
104104 return await DocumentColorHandler . doDocumentColorRequest ( document . uri ) ;
105105 } ) ;
106106
107- registerRequestHandler < ColorPresentationParams , ColorPresentation [ ] > (
108- ColorPresentationRequest . method ,
109- async ( params ) => {
110- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
111- const document = await documentManager . getDocument ( uri ) ;
107+ registerRequestHandler ( ColorPresentationRequest . type , async ( params ) => {
108+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
109+ const document = await documentManager . getDocument ( uri ) ;
112110
113- return await ColorPresentationHandler . doColorPresentationRequest ( document . uri , params ) ;
114- }
115- ) ;
111+ return await ColorPresentationHandler . doColorPresentationRequest ( document . uri , params ) ;
112+ } ) ;
116113
117- registerRequestHandler < FoldingRangeParams , FoldingRange [ ] > ( FoldingRangeRequest . method , async ( params ) => {
114+ registerRequestHandler ( FoldingRangeRequest . type , async ( params ) => {
118115 const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
119116 const document = await documentManager . getDocument ( uri ) ;
120117
@@ -126,7 +123,7 @@ export function registerRazorEndpoints(
126123 return FoldingRangeHandler . convertFoldingRanges ( results , razorLogger ) ;
127124 } ) ;
128125
129- registerRequestHandler < HoverParams , Hover | undefined > ( HoverRequest . method , async ( params ) => {
126+ registerRequestHandler ( HoverRequest . type , async ( params ) => {
130127 const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
131128 const document = await documentManager . getDocument ( uri ) ;
132129
@@ -140,23 +137,20 @@ export function registerRazorEndpoints(
140137 return rewriteHover ( applicableHover ) ;
141138 } ) ;
142139
143- registerRequestHandler < DocumentHighlightParams , DocumentHighlight [ ] > (
144- DocumentHighlightRequest . method ,
145- async ( params ) => {
146- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
147- const document = await documentManager . getDocument ( uri ) ;
140+ registerRequestHandler ( DocumentHighlightRequest . type , async ( params ) => {
141+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
142+ const document = await documentManager . getDocument ( uri ) ;
148143
149- const results = await vscode . commands . executeCommand < vscode . DocumentHighlight [ ] > (
150- 'vscode.executeDocumentHighlights' ,
151- document . uri ,
152- params . position
153- ) ;
144+ const results = await vscode . commands . executeCommand < vscode . DocumentHighlight [ ] > (
145+ 'vscode.executeDocumentHighlights' ,
146+ document . uri ,
147+ params . position
148+ ) ;
154149
155- return rewriteHighlight ( results ) ;
156- }
157- ) ;
150+ return rewriteHighlight ( results ) ;
151+ } ) ;
158152
159- registerRequestHandler < CompletionParams , CompletionList > ( CompletionRequest . method , async ( params ) => {
153+ registerRequestHandler ( CompletionRequest . type , async ( params ) => {
160154 const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
161155 const document = await documentManager . getDocument ( uri ) ;
162156
@@ -167,7 +161,7 @@ export function registerRazorEndpoints(
167161 ) ;
168162 } ) ;
169163
170- registerRequestHandler < ReferenceParams , Location [ ] > ( ReferencesRequest . method , async ( params ) => {
164+ registerRequestHandler ( ReferencesRequest . type , async ( params ) => {
171165 const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
172166 const document = await documentManager . getDocument ( uri ) ;
173167
@@ -180,7 +174,7 @@ export function registerRazorEndpoints(
180174 return rewriteLocations ( results ) ;
181175 } ) ;
182176
183- registerRequestHandler < ImplementationParams , Location [ ] > ( ImplementationRequest . method , async ( params ) => {
177+ registerRequestHandler ( ImplementationRequest . type , async ( params ) => {
184178 const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
185179 const document = await documentManager . getDocument ( uri ) ;
186180
@@ -193,7 +187,7 @@ export function registerRazorEndpoints(
193187 return rewriteLocations ( results ) ;
194188 } ) ;
195189
196- registerRequestHandler < DefinitionParams , Location [ ] > ( DefinitionRequest . method , async ( params ) => {
190+ registerRequestHandler ( DefinitionRequest . type , async ( params ) => {
197191 const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
198192 const document = await documentManager . getDocument ( uri ) ;
199193
@@ -206,77 +200,68 @@ export function registerRazorEndpoints(
206200 return rewriteLocations ( results ) ;
207201 } ) ;
208202
209- registerRequestHandler < SignatureHelpParams , SignatureHelp | undefined > (
210- SignatureHelpRequest . method ,
211- async ( params ) => {
212- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
213- const document = await documentManager . getDocument ( uri ) ;
214-
215- const results = await vscode . commands . executeCommand < vscode . SignatureHelp > (
216- 'vscode.executeSignatureHelpProvider' ,
217- document . uri ,
218- params . position
219- ) ;
203+ registerRequestHandler ( SignatureHelpRequest . type , async ( params ) => {
204+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
205+ const document = await documentManager . getDocument ( uri ) ;
220206
221- if ( ! results ) {
222- return undefined ;
223- }
207+ const results = await vscode . commands . executeCommand < vscode . SignatureHelp > (
208+ 'vscode.executeSignatureHelpProvider' ,
209+ document . uri ,
210+ params . position
211+ ) ;
224212
225- return rewriteSignatureHelp ( results ) ;
213+ if ( ! results ) {
214+ return undefined ;
226215 }
227- ) ;
228216
229- registerRequestHandler < DocumentFormattingParams , TextEdit [ ] | undefined > (
230- DocumentFormattingRequest . method ,
231- async ( params ) => {
232- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
233- const document = await documentManager . getDocument ( uri ) ;
217+ return rewriteSignatureHelp ( results ) ;
218+ } ) ;
234219
235- const content = document . getContent ( ) ;
236- const options = < vscode . FormattingOptions > params . options ;
220+ registerRequestHandler ( DocumentFormattingRequest . type , async ( params ) => {
221+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
222+ const document = await documentManager . getDocument ( uri ) ;
237223
238- const response = await FormattingHandler . getHtmlFormattingResult ( document . uri , content , options ) ;
239- return response ?. edits ;
240- }
241- ) ;
224+ const content = document . getContent ( ) ;
225+ const options = < vscode . FormattingOptions > params . options ;
242226
243- registerRequestHandler < DocumentOnTypeFormattingParams , TextEdit [ ] | undefined > (
244- DocumentOnTypeFormattingRequest . method ,
245- async ( params ) => {
246- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
247- const document = await documentManager . getDocument ( uri ) ;
248-
249- const content = document . getContent ( ) ;
250- const options = < vscode . FormattingOptions > params . options ;
251-
252- const response = await FormattingHandler . getHtmlOnTypeFormattingResult (
253- document . uri ,
254- content ,
255- params . position ,
256- params . ch ,
257- options
258- ) ;
259- return response ?. edits ;
260- }
261- ) ;
227+ const response = await FormattingHandler . getHtmlFormattingResult ( document . uri , content , options ) ;
228+ return response ?. edits ;
229+ } ) ;
230+
231+ registerRequestHandler ( DocumentOnTypeFormattingRequest . type , async ( params ) => {
232+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
233+ const document = await documentManager . getDocument ( uri ) ;
234+
235+ const content = document . getContent ( ) ;
236+ const options = < vscode . FormattingOptions > params . options ;
237+
238+ const response = await FormattingHandler . getHtmlOnTypeFormattingResult (
239+ document . uri ,
240+ content ,
241+ params . position ,
242+ params . ch ,
243+ options
244+ ) ;
245+ return response ?. edits ;
246+ } ) ;
262247 }
263248
264249 function registerNonCohostingEndpoints ( ) {
265- registerRequestHandler < ProvideDynamicFileParams , ProvideDynamicFileResponse > (
250+ registerMethodHandler < ProvideDynamicFileParams , ProvideDynamicFileResponse > (
266251 'razor/provideDynamicFileInfo' ,
267252 async ( params ) =>
268253 vscode . commands . executeCommand ( DynamicFileInfoHandler . provideDynamicFileInfoCommand , params )
269254 ) ;
270255
271- registerRequestHandler < ProvideDynamicFileParams , ProvideDynamicFileResponse > (
256+ registerMethodHandler < ProvideDynamicFileParams , ProvideDynamicFileResponse > (
272257 'razor/removeDynamicFileInfo' ,
273258 async ( params ) =>
274259 vscode . commands . executeCommand ( DynamicFileInfoHandler . provideDynamicFileInfoCommand , params )
275260 ) ;
276- registerRequestHandler < RazorMapSpansParams , RazorMapSpansResponse > ( 'razor/mapSpans' , async ( params ) => {
261+ registerMethodHandler < RazorMapSpansParams , RazorMapSpansResponse > ( 'razor/mapSpans' , async ( params ) => {
277262 return await vscode . commands . executeCommand < RazorMapSpansResponse > ( MappingHandler . MapSpansCommand , params ) ;
278263 } ) ;
279- registerRequestHandler < RazorMapTextChangesParams , RazorMapTextChangesResponse > (
264+ registerMethodHandler < RazorMapTextChangesParams , RazorMapTextChangesResponse > (
280265 'razor/mapTextChanges' ,
281266 async ( params ) => {
282267 return await vscode . commands . executeCommand < RazorMapTextChangesResponse > (
@@ -288,7 +273,14 @@ export function registerRazorEndpoints(
288273 }
289274
290275 // Helper method that registers a request handler, and logs errors to the Razor logger.
291- function registerRequestHandler < Params , Result > ( method : string , invocation : ( params : Params ) => Promise < Result > ) {
276+ function registerRequestHandler < Params , Result , Error > (
277+ type : RequestType < Params , Result , Error > ,
278+ invocation : ( params : Params ) => Promise < Result >
279+ ) {
280+ return registerMethodHandler < Params , Result > ( type . method , invocation ) ;
281+ }
282+
283+ function registerMethodHandler < Params , Result > ( method : string , invocation : ( params : Params ) => Promise < Result > ) {
292284 const requestType = new RequestType < Params , Result , Error > ( method ) ;
293285 roslynLanguageServer . registerOnRequest ( requestType , async ( params ) => {
294286 try {
0 commit comments