@@ -24,6 +24,9 @@ import { DocumentColorHandler } from '../../razor/src/documentColor/documentColo
24
24
import { razorOptions } from '../../shared/options' ;
25
25
import { ColorPresentationHandler } from '../../razor/src/colorPresentation/colorPresentationHandler' ;
26
26
import { 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' ;
27
30
28
31
export function registerRazorEndpoints (
29
32
context : vscode . ExtensionContext ,
@@ -36,34 +39,59 @@ export function registerRazorEndpoints(
36
39
razorLogger . log ( params . message , params . type )
37
40
) ;
38
41
39
- if ( ! razorOptions . cohostingEnabled ) {
40
- return ;
42
+ if ( razorOptions . cohostingEnabled ) {
43
+ registerCohostingEndpoints ( ) ;
44
+ } else {
45
+ registerNonCohostingEndpoints ( ) ;
41
46
}
42
47
43
- const documentManager = new HtmlDocumentManager ( platformInfo , razorLogger ) ;
44
- context . subscriptions . push ( documentManager . register ( ) ) ;
48
+ return ;
45
49
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 ( ) ) ;
50
56
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
+ } ) ;
57
61
58
- registerRequestHandler < ColorPresentationParams , ColorPresentation [ ] > (
59
- ColorPresentationRequest . method ,
60
- async ( params ) => {
62
+ registerRequestHandler < DocumentColorParams , ColorInformation [ ] > ( DocumentColorRequest . method , async ( params ) => {
61
63
const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
62
64
const document = await documentManager . getDocument ( uri ) ;
63
65
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
+ }
67
95
68
96
// Helper method that registers a request handler, and logs errors to the Razor logger.
69
97
function registerRequestHandler < Params , Result > ( method : string , invocation : ( params : Params ) => Promise < Result > ) {
0 commit comments