@@ -24,6 +24,9 @@ import { DocumentColorHandler } from '../../razor/src/documentColor/documentColo
2424import { razorOptions } from '../../shared/options' ;
2525import { ColorPresentationHandler } from '../../razor/src/colorPresentation/colorPresentationHandler' ;
2626import { ColorPresentation } from 'vscode-html-languageservice' ;
27+ import { DynamicFileInfoHandler } from '../../razor/src/dynamicFile/dynamicFileInfoHandler' ;
28+ import { ProvideDynamicFileParams } from '../../razor/src/dynamicFile/provideDynamicFileParams' ;
29+ import { ProvideDynamicFileResponse } from '../../razor/src/dynamicFile/provideDynamicFileResponse' ;
2730
2831export function registerRazorEndpoints (
2932 context : vscode . ExtensionContext ,
@@ -36,34 +39,59 @@ export function registerRazorEndpoints(
3639 razorLogger . log ( params . message , params . type )
3740 ) ;
3841
39- if ( ! razorOptions . cohostingEnabled ) {
40- return ;
42+ if ( razorOptions . cohostingEnabled ) {
43+ registerCohostingEndpoints ( ) ;
44+ } else {
45+ registerNonCohostingEndpoints ( ) ;
4146 }
4247
43- const documentManager = new HtmlDocumentManager ( platformInfo , razorLogger ) ;
44- context . subscriptions . push ( documentManager . register ( ) ) ;
48+ return ;
4549
46- registerRequestHandler < HtmlUpdateParameters , void > ( 'razor/updateHtml' , async ( params ) => {
47- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
48- await documentManager . updateDocumentText ( uri , params . text ) ;
49- } ) ;
50+ //
51+ // Local Functions
52+ //
53+ function registerCohostingEndpoints ( ) {
54+ const documentManager = new HtmlDocumentManager ( platformInfo , razorLogger ) ;
55+ context . subscriptions . push ( documentManager . register ( ) ) ;
5056
51- registerRequestHandler < DocumentColorParams , ColorInformation [ ] > ( DocumentColorRequest . method , async ( params ) => {
52- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
53- const document = await documentManager . getDocument ( uri ) ;
54-
55- return await DocumentColorHandler . doDocumentColorRequest ( document . uri ) ;
56- } ) ;
57+ registerRequestHandler < HtmlUpdateParameters , void > ( 'razor/updateHtml' , async ( params ) => {
58+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
59+ await documentManager . updateDocumentText ( uri , params . text ) ;
60+ } ) ;
5761
58- registerRequestHandler < ColorPresentationParams , ColorPresentation [ ] > (
59- ColorPresentationRequest . method ,
60- async ( params ) => {
62+ registerRequestHandler < DocumentColorParams , ColorInformation [ ] > ( DocumentColorRequest . method , async ( params ) => {
6163 const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
6264 const document = await documentManager . getDocument ( uri ) ;
6365
64- return await ColorPresentationHandler . doColorPresentationRequest ( document . uri , params ) ;
65- }
66- ) ;
66+ return await DocumentColorHandler . doDocumentColorRequest ( document . uri ) ;
67+ } ) ;
68+
69+ registerRequestHandler < ColorPresentationParams , ColorPresentation [ ] > (
70+ ColorPresentationRequest . method ,
71+ async ( params ) => {
72+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
73+ const document = await documentManager . getDocument ( uri ) ;
74+
75+ return await ColorPresentationHandler . doColorPresentationRequest ( document . uri , params ) ;
76+ }
77+ ) ;
78+ }
79+
80+ function registerNonCohostingEndpoints ( ) {
81+ // When the Roslyn language server sends a request for Razor dynamic file info, we forward that request along to Razor via
82+ // a command.
83+ registerRequestHandler < ProvideDynamicFileParams , ProvideDynamicFileResponse > (
84+ 'razor/provideDynamicFileInfo' ,
85+ async ( params ) =>
86+ vscode . commands . executeCommand ( DynamicFileInfoHandler . provideDynamicFileInfoCommand , params )
87+ ) ;
88+
89+ registerRequestHandler < ProvideDynamicFileParams , ProvideDynamicFileResponse > (
90+ 'razor/removeDynamicFileInfo' ,
91+ async ( params ) =>
92+ vscode . commands . executeCommand ( DynamicFileInfoHandler . provideDynamicFileInfoCommand , params )
93+ ) ;
94+ }
6795
6896 // Helper method that registers a request handler, and logs errors to the Razor logger.
6997 function registerRequestHandler < Params , Result > ( method : string , invocation : ( params : Params ) => Promise < Result > ) {
0 commit comments