@@ -50,6 +50,8 @@ import { RazorMapTextChangesParams } from '../../razor/src/mapping/razorMapTextC
50
50
import { RazorMapTextChangesResponse } from '../../razor/src/mapping/razorMapTextChangesResponse' ;
51
51
import { FormattingHandler } from '../../razor/src/formatting/formattingHandler' ;
52
52
import { ReportIssueCommand } from '../../razor/src/diagnostics/reportIssueCommand' ;
53
+ import { HtmlDocument } from './htmlDocument' ;
54
+ import { HtmlForwardedRequest } from './htmlForwardedRequest' ;
53
55
54
56
export function registerRazorEndpoints (
55
57
context : vscode . ExtensionContext ,
@@ -76,34 +78,25 @@ export function registerRazorEndpoints(
76
78
// Local Functions
77
79
//
78
80
function registerCohostingEndpoints ( ) {
79
- const documentManager = new HtmlDocumentManager ( platformInfo , razorLogger ) ;
81
+ const documentManager = new HtmlDocumentManager ( platformInfo , roslynLanguageServer , razorLogger ) ;
80
82
const reportIssueCommand = new ReportIssueCommand ( vscode , undefined , documentManager , razorLogger ) ;
81
83
context . subscriptions . push ( documentManager . register ( ) ) ;
82
84
context . subscriptions . push ( reportIssueCommand . register ( ) ) ;
83
85
84
86
registerMethodHandler < HtmlUpdateParameters , void > ( 'razor/updateHtml' , async ( params ) => {
85
87
const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
86
- await documentManager . updateDocumentText ( uri , params . text ) ;
88
+ await documentManager . updateDocumentText ( uri , params . checksum , params . text ) ;
87
89
} ) ;
88
90
89
- registerRequestHandler ( DocumentColorRequest . type , async ( params ) => {
90
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
91
- const document = await documentManager . getDocument ( uri ) ;
92
-
91
+ registerCohostHandler ( DocumentColorRequest . type , documentManager , async ( document ) => {
93
92
return await DocumentColorHandler . doDocumentColorRequest ( document . uri ) ;
94
93
} ) ;
95
94
96
- registerRequestHandler ( ColorPresentationRequest . type , async ( params ) => {
97
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
98
- const document = await documentManager . getDocument ( uri ) ;
99
-
95
+ registerCohostHandler ( ColorPresentationRequest . type , documentManager , async ( document , params ) => {
100
96
return await ColorPresentationHandler . doColorPresentationRequest ( document . uri , params ) ;
101
97
} ) ;
102
98
103
- registerRequestHandler ( FoldingRangeRequest . type , async ( params ) => {
104
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
105
- const document = await documentManager . getDocument ( uri ) ;
106
-
99
+ registerCohostHandler ( FoldingRangeRequest . type , documentManager , async ( document ) => {
107
100
const results = await vscode . commands . executeCommand < vscode . FoldingRange [ ] > (
108
101
'vscode.executeFoldingRangeProvider' ,
109
102
document . uri
@@ -112,10 +105,7 @@ export function registerRazorEndpoints(
112
105
return FoldingRangeHandler . convertFoldingRanges ( results , razorLogger ) ;
113
106
} ) ;
114
107
115
- registerRequestHandler ( HoverRequest . type , async ( params ) => {
116
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
117
- const document = await documentManager . getDocument ( uri ) ;
118
-
108
+ registerCohostHandler ( HoverRequest . type , documentManager , async ( document , params ) => {
119
109
const results = await vscode . commands . executeCommand < vscode . Hover [ ] > (
120
110
'vscode.executeHoverProvider' ,
121
111
document . uri ,
@@ -126,10 +116,7 @@ export function registerRazorEndpoints(
126
116
return rewriteHover ( applicableHover ) ;
127
117
} ) ;
128
118
129
- registerRequestHandler ( DocumentHighlightRequest . type , async ( params ) => {
130
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
131
- const document = await documentManager . getDocument ( uri ) ;
132
-
119
+ registerCohostHandler ( DocumentHighlightRequest . type , documentManager , async ( document , params ) => {
133
120
const results = await vscode . commands . executeCommand < vscode . DocumentHighlight [ ] > (
134
121
'vscode.executeDocumentHighlights' ,
135
122
document . uri ,
@@ -139,21 +126,15 @@ export function registerRazorEndpoints(
139
126
return rewriteHighlight ( results ) ;
140
127
} ) ;
141
128
142
- registerRequestHandler ( CompletionRequest . type , async ( params ) => {
143
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
144
- const document = await documentManager . getDocument ( uri ) ;
145
-
129
+ registerCohostHandler ( CompletionRequest . type , documentManager , async ( document , params ) => {
146
130
return CompletionHandler . provideVscodeCompletions (
147
131
document . uri ,
148
132
params . position ,
149
133
params . context ?. triggerCharacter
150
134
) ;
151
135
} ) ;
152
136
153
- registerRequestHandler ( ReferencesRequest . type , async ( params ) => {
154
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
155
- const document = await documentManager . getDocument ( uri ) ;
156
-
137
+ registerCohostHandler ( ReferencesRequest . type , documentManager , async ( document , params ) => {
157
138
const results = await vscode . commands . executeCommand < vscode . Location [ ] > (
158
139
'vscode.executeReferenceProvider' ,
159
140
document . uri ,
@@ -163,10 +144,7 @@ export function registerRazorEndpoints(
163
144
return rewriteLocations ( results ) ;
164
145
} ) ;
165
146
166
- registerRequestHandler ( ImplementationRequest . type , async ( params ) => {
167
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
168
- const document = await documentManager . getDocument ( uri ) ;
169
-
147
+ registerCohostHandler ( ImplementationRequest . type , documentManager , async ( document , params ) => {
170
148
const results = await vscode . commands . executeCommand < vscode . Location [ ] > (
171
149
'vscode.executeImplementationProvider' ,
172
150
document . uri ,
@@ -176,10 +154,7 @@ export function registerRazorEndpoints(
176
154
return rewriteLocations ( results ) ;
177
155
} ) ;
178
156
179
- registerRequestHandler ( DefinitionRequest . type , async ( params ) => {
180
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
181
- const document = await documentManager . getDocument ( uri ) ;
182
-
157
+ registerCohostHandler ( DefinitionRequest . type , documentManager , async ( document , params ) => {
183
158
const results = await vscode . commands . executeCommand < vscode . Location [ ] > (
184
159
'vscode.executeDefinitionProvider' ,
185
160
document . uri ,
@@ -189,10 +164,7 @@ export function registerRazorEndpoints(
189
164
return rewriteLocations ( results ) ;
190
165
} ) ;
191
166
192
- registerRequestHandler ( SignatureHelpRequest . type , async ( params ) => {
193
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
194
- const document = await documentManager . getDocument ( uri ) ;
195
-
167
+ registerCohostHandler ( SignatureHelpRequest . type , documentManager , async ( document , params ) => {
196
168
const results = await vscode . commands . executeCommand < vscode . SignatureHelp > (
197
169
'vscode.executeSignatureHelpProvider' ,
198
170
document . uri ,
@@ -206,21 +178,15 @@ export function registerRazorEndpoints(
206
178
return rewriteSignatureHelp ( results ) ;
207
179
} ) ;
208
180
209
- registerRequestHandler ( DocumentFormattingRequest . type , async ( params ) => {
210
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
211
- const document = await documentManager . getDocument ( uri ) ;
212
-
181
+ registerCohostHandler ( DocumentFormattingRequest . type , documentManager , async ( document , params ) => {
213
182
const content = document . getContent ( ) ;
214
183
const options = < vscode . FormattingOptions > params . options ;
215
184
216
185
const response = await FormattingHandler . getHtmlFormattingResult ( document . uri , content , options ) ;
217
186
return response ?. edits ;
218
187
} ) ;
219
188
220
- registerRequestHandler ( DocumentOnTypeFormattingRequest . type , async ( params ) => {
221
- const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
222
- const document = await documentManager . getDocument ( uri ) ;
223
-
189
+ registerCohostHandler ( DocumentOnTypeFormattingRequest . type , documentManager , async ( document , params ) => {
224
190
const content = document . getContent ( ) ;
225
191
const options = < vscode . FormattingOptions > params . options ;
226
192
@@ -262,11 +228,21 @@ export function registerRazorEndpoints(
262
228
}
263
229
264
230
// Helper method that registers a request handler, and logs errors to the Razor logger.
265
- function registerRequestHandler < Params , Result , Error > (
231
+ function registerCohostHandler < Params , Result , Error > (
266
232
type : RequestType < Params , Result , Error > ,
267
- invocation : ( params : Params ) => Promise < Result >
233
+ documentManager : HtmlDocumentManager ,
234
+ invocation : ( document : HtmlDocument , request : Params ) => Promise < Result >
268
235
) {
269
- return registerMethodHandler < Params , Result > ( type . method , invocation ) ;
236
+ return registerMethodHandler < HtmlForwardedRequest < Params > , Result | undefined > ( type . method , async ( params ) => {
237
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
238
+ const document = await documentManager . getDocument ( uri , params . checksum ) ;
239
+
240
+ if ( ! document ) {
241
+ return undefined ;
242
+ }
243
+
244
+ return invocation ( document , params . request ) ;
245
+ } ) ;
270
246
}
271
247
272
248
function registerMethodHandler < Params , Result > ( method : string , invocation : ( params : Params ) => Promise < Result > ) {
0 commit comments