@@ -41,104 +41,147 @@ import { ColorPresentation } from 'vscode-html-languageservice';
41
41
import { convertRangeToSerializable } from '../../razor/src/rpc/serializableRange' ;
42
42
import { FoldingRangeHandler } from '../../razor/src/folding/foldingRangeHandler' ;
43
43
import { CompletionHandler } from '../../razor/src/completion/completionHandler' ;
44
+ import { DynamicFileInfoHandler } from '../../razor/src/dynamicFile/dynamicFileInfoHandler' ;
45
+ import { ProvideDynamicFileParams } from '../../razor/src/dynamicFile/provideDynamicFileParams' ;
46
+ import { ProvideDynamicFileResponse } from '../../razor/src/dynamicFile/provideDynamicFileResponse' ;
47
+ import { RazorMapSpansParams } from '../../razor/src/mapping/razorMapSpansParams' ;
48
+ import { RazorMapSpansResponse } from '../../razor/src/mapping/razorMapSpansResponse' ;
49
+ import { MappingHandler } from '../../razor/src/mapping/mappingHandler' ;
50
+ import { RazorMapTextChangesParams } from '../../razor/src/mapping/razorMapTextChangesParams' ;
51
+ import { RazorMapTextChangesResponse } from '../../razor/src/mapping/razorMapTextChangesResponse' ;
44
52
45
53
export function registerRazorEndpoints (
46
54
context : vscode . ExtensionContext ,
47
- languageServer : RoslynLanguageServer ,
55
+ roslynLanguageServer : RoslynLanguageServer ,
48
56
razorLogger : RazorLogger ,
49
57
platformInfo : PlatformInformation
50
58
) {
51
59
const logNotificationType = new NotificationType < LogMessageParams > ( 'razor/log' ) ;
52
- languageServer . registerOnNotificationWithParams ( logNotificationType , ( params ) =>
60
+ roslynLanguageServer . registerOnNotificationWithParams ( logNotificationType , ( params ) =>
53
61
razorLogger . log ( params . message , params . type )
54
62
) ;
55
63
56
- if ( ! razorOptions . cohostingEnabled ) {
57
- return ;
64
+ if ( razorOptions . cohostingEnabled ) {
65
+ registerCohostingEndpoints ( ) ;
66
+ } else {
67
+ registerNonCohostingEndpoints ( ) ;
58
68
}
59
69
60
- const documentManager = new HtmlDocumentManager ( platformInfo , razorLogger ) ;
61
- context . subscriptions . push ( documentManager . register ( ) ) ;
70
+ return ;
62
71
63
- registerRequestHandler < HtmlUpdateParameters , void > ( 'razor/updateHtml' , async ( params ) => {
64
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
65
- await documentManager . updateDocumentText ( uri , params . text ) ;
66
- } ) ;
67
-
68
- registerRequestHandler < DocumentColorParams , ColorInformation [ ] > ( DocumentColorRequest . method , async ( params ) => {
69
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
70
- const document = await documentManager . getDocument ( uri ) ;
72
+ //
73
+ // Local Functions
74
+ //
75
+ function registerCohostingEndpoints ( ) {
76
+ const documentManager = new HtmlDocumentManager ( platformInfo , razorLogger ) ;
77
+ context . subscriptions . push ( documentManager . register ( ) ) ;
71
78
72
- return await DocumentColorHandler . doDocumentColorRequest ( document . uri ) ;
73
- } ) ;
79
+ registerRequestHandler < HtmlUpdateParameters , void > ( 'razor/updateHtml' , async ( params ) => {
80
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
81
+ await documentManager . updateDocumentText ( uri , params . text ) ;
82
+ } ) ;
74
83
75
- registerRequestHandler < ColorPresentationParams , ColorPresentation [ ] > (
76
- ColorPresentationRequest . method ,
77
- async ( params ) => {
84
+ registerRequestHandler < DocumentColorParams , ColorInformation [ ] > ( DocumentColorRequest . method , async ( params ) => {
78
85
const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
79
86
const document = await documentManager . getDocument ( uri ) ;
80
87
81
- return await ColorPresentationHandler . doColorPresentationRequest ( document . uri , params ) ;
82
- }
83
- ) ;
88
+ return await DocumentColorHandler . doDocumentColorRequest ( document . uri ) ;
89
+ } ) ;
84
90
85
- registerRequestHandler < FoldingRangeParams , FoldingRange [ ] > ( FoldingRangeRequest . method , async ( params ) => {
86
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
87
- const document = await documentManager . getDocument ( uri ) ;
91
+ registerRequestHandler < ColorPresentationParams , ColorPresentation [ ] > (
92
+ ColorPresentationRequest . method ,
93
+ async ( params ) => {
94
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
95
+ const document = await documentManager . getDocument ( uri ) ;
88
96
89
- const results = await vscode . commands . executeCommand < vscode . FoldingRange [ ] > (
90
- 'vscode.executeFoldingRangeProvider' ,
91
- document . uri
97
+ return await ColorPresentationHandler . doColorPresentationRequest ( document . uri , params ) ;
98
+ }
92
99
) ;
93
100
94
- return FoldingRangeHandler . convertFoldingRanges ( results , razorLogger ) ;
95
- } ) ;
96
-
97
- registerRequestHandler < HoverParams , Hover | undefined > ( HoverRequest . method , async ( params ) => {
98
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
99
- const document = await documentManager . getDocument ( uri ) ;
101
+ registerRequestHandler < FoldingRangeParams , FoldingRange [ ] > ( FoldingRangeRequest . method , async ( params ) => {
102
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
103
+ const document = await documentManager . getDocument ( uri ) ;
100
104
101
- const results = await vscode . commands . executeCommand < vscode . Hover [ ] > (
102
- 'vscode.executeHoverProvider' ,
103
- document . uri ,
104
- params . position
105
- ) ;
106
- const applicableHover = results . filter ( ( item ) => item . range ) [ 0 ] ;
105
+ const results = await vscode . commands . executeCommand < vscode . FoldingRange [ ] > (
106
+ 'vscode.executeFoldingRangeProvider' ,
107
+ document . uri
108
+ ) ;
107
109
108
- return rewriteHover ( applicableHover ) ;
109
- } ) ;
110
+ return FoldingRangeHandler . convertFoldingRanges ( results , razorLogger ) ;
111
+ } ) ;
110
112
111
- registerRequestHandler < DocumentHighlightParams , DocumentHighlight [ ] > (
112
- DocumentHighlightRequest . method ,
113
- async ( params ) => {
113
+ registerRequestHandler < HoverParams , Hover | undefined > ( HoverRequest . method , async ( params ) => {
114
114
const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
115
115
const document = await documentManager . getDocument ( uri ) ;
116
116
117
- const results = await vscode . commands . executeCommand < vscode . DocumentHighlight [ ] > (
118
- 'vscode.executeDocumentHighlights ' ,
117
+ const results = await vscode . commands . executeCommand < vscode . Hover [ ] > (
118
+ 'vscode.executeHoverProvider ' ,
119
119
document . uri ,
120
120
params . position
121
121
) ;
122
+ const applicableHover = results . filter ( ( item ) => item . range ) [ 0 ] ;
122
123
123
- return rewriteHighlight ( results ) ;
124
- }
125
- ) ;
124
+ return rewriteHover ( applicableHover ) ;
125
+ } ) ;
126
126
127
- registerRequestHandler < CompletionParams , CompletionList > ( CompletionRequest . method , async ( params ) => {
128
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
129
- const document = await documentManager . getDocument ( uri ) ;
127
+ registerRequestHandler < DocumentHighlightParams , DocumentHighlight [ ] > (
128
+ DocumentHighlightRequest . method ,
129
+ async ( params ) => {
130
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
131
+ const document = await documentManager . getDocument ( uri ) ;
130
132
131
- return CompletionHandler . provideVscodeCompletions (
132
- document . uri ,
133
- params . position ,
134
- params . context ?. triggerCharacter
133
+ const results = await vscode . commands . executeCommand < vscode . DocumentHighlight [ ] > (
134
+ 'vscode.executeDocumentHighlights' ,
135
+ document . uri ,
136
+ params . position
137
+ ) ;
138
+
139
+ return rewriteHighlight ( results ) ;
140
+ }
135
141
) ;
136
- } ) ;
142
+
143
+ registerRequestHandler < CompletionParams , CompletionList > ( CompletionRequest . method , async ( params ) => {
144
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
145
+ const document = await documentManager . getDocument ( uri ) ;
146
+
147
+ return CompletionHandler . provideVscodeCompletions (
148
+ document . uri ,
149
+ params . position ,
150
+ params . context ?. triggerCharacter
151
+ ) ;
152
+ } ) ;
153
+ }
154
+
155
+ function registerNonCohostingEndpoints ( ) {
156
+ registerRequestHandler < ProvideDynamicFileParams , ProvideDynamicFileResponse > (
157
+ 'razor/provideDynamicFileInfo' ,
158
+ async ( params ) =>
159
+ vscode . commands . executeCommand ( DynamicFileInfoHandler . provideDynamicFileInfoCommand , params )
160
+ ) ;
161
+
162
+ registerRequestHandler < ProvideDynamicFileParams , ProvideDynamicFileResponse > (
163
+ 'razor/removeDynamicFileInfo' ,
164
+ async ( params ) =>
165
+ vscode . commands . executeCommand ( DynamicFileInfoHandler . provideDynamicFileInfoCommand , params )
166
+ ) ;
167
+ registerRequestHandler < RazorMapSpansParams , RazorMapSpansResponse > ( 'razor/mapSpans' , async ( params ) => {
168
+ return await vscode . commands . executeCommand < RazorMapSpansResponse > ( MappingHandler . MapSpansCommand , params ) ;
169
+ } ) ;
170
+ registerRequestHandler < RazorMapTextChangesParams , RazorMapTextChangesResponse > (
171
+ 'razor/mapTextChanges' ,
172
+ async ( params ) => {
173
+ return await vscode . commands . executeCommand < RazorMapTextChangesResponse > (
174
+ MappingHandler . MapChangesCommand ,
175
+ params
176
+ ) ;
177
+ }
178
+ ) ;
179
+ }
137
180
138
181
// Helper method that registers a request handler, and logs errors to the Razor logger.
139
182
function registerRequestHandler < Params , Result > ( method : string , invocation : ( params : Params ) => Promise < Result > ) {
140
183
const requestType = new RequestType < Params , Result , Error > ( method ) ;
141
- languageServer . registerOnRequest ( requestType , async ( params ) => {
184
+ roslynLanguageServer . registerOnRequest ( requestType , async ( params ) => {
142
185
try {
143
186
return await invocation ( params ) ;
144
187
} catch ( error ) {
0 commit comments