@@ -50,6 +50,8 @@ import { RazorMapTextChangesParams } from '../../razor/src/mapping/razorMapTextC
5050import { RazorMapTextChangesResponse } from '../../razor/src/mapping/razorMapTextChangesResponse' ;
5151import { FormattingHandler } from '../../razor/src/formatting/formattingHandler' ;
5252import { ReportIssueCommand } from '../../razor/src/diagnostics/reportIssueCommand' ;
53+ import { HtmlDocument } from './htmlDocument' ;
54+ import { HtmlForwardedRequest } from './htmlForwardedRequest' ;
5355
5456export function registerRazorEndpoints (
5557 context : vscode . ExtensionContext ,
@@ -76,34 +78,25 @@ export function registerRazorEndpoints(
7678 // Local Functions
7779 //
7880 function registerCohostingEndpoints ( ) {
79- const documentManager = new HtmlDocumentManager ( platformInfo , razorLogger ) ;
81+ const documentManager = new HtmlDocumentManager ( platformInfo , roslynLanguageServer , razorLogger ) ;
8082 const reportIssueCommand = new ReportIssueCommand ( vscode , undefined , documentManager , razorLogger ) ;
8183 context . subscriptions . push ( documentManager . register ( ) ) ;
8284 context . subscriptions . push ( reportIssueCommand . register ( ) ) ;
8385
8486 registerMethodHandler < HtmlUpdateParameters , void > ( 'razor/updateHtml' , async ( params ) => {
8587 const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
86- await documentManager . updateDocumentText ( uri , params . text ) ;
88+ await documentManager . updateDocumentText ( uri , params . checksum , params . text ) ;
8789 } ) ;
8890
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 ) => {
9392 return await DocumentColorHandler . doDocumentColorRequest ( document . uri ) ;
9493 } ) ;
9594
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 ) => {
10096 return await ColorPresentationHandler . doColorPresentationRequest ( document . uri , params ) ;
10197 } ) ;
10298
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 ) => {
107100 const results = await vscode . commands . executeCommand < vscode . FoldingRange [ ] > (
108101 'vscode.executeFoldingRangeProvider' ,
109102 document . uri
@@ -112,10 +105,7 @@ export function registerRazorEndpoints(
112105 return FoldingRangeHandler . convertFoldingRanges ( results , razorLogger ) ;
113106 } ) ;
114107
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 ) => {
119109 const results = await vscode . commands . executeCommand < vscode . Hover [ ] > (
120110 'vscode.executeHoverProvider' ,
121111 document . uri ,
@@ -126,10 +116,7 @@ export function registerRazorEndpoints(
126116 return rewriteHover ( applicableHover ) ;
127117 } ) ;
128118
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 ) => {
133120 const results = await vscode . commands . executeCommand < vscode . DocumentHighlight [ ] > (
134121 'vscode.executeDocumentHighlights' ,
135122 document . uri ,
@@ -139,21 +126,15 @@ export function registerRazorEndpoints(
139126 return rewriteHighlight ( results ) ;
140127 } ) ;
141128
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 ) => {
146130 return CompletionHandler . provideVscodeCompletions (
147131 document . uri ,
148132 params . position ,
149133 params . context ?. triggerCharacter
150134 ) ;
151135 } ) ;
152136
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 ) => {
157138 const results = await vscode . commands . executeCommand < vscode . Location [ ] > (
158139 'vscode.executeReferenceProvider' ,
159140 document . uri ,
@@ -163,10 +144,7 @@ export function registerRazorEndpoints(
163144 return rewriteLocations ( results ) ;
164145 } ) ;
165146
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 ) => {
170148 const results = await vscode . commands . executeCommand < vscode . Location [ ] > (
171149 'vscode.executeImplementationProvider' ,
172150 document . uri ,
@@ -176,10 +154,7 @@ export function registerRazorEndpoints(
176154 return rewriteLocations ( results ) ;
177155 } ) ;
178156
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 ) => {
183158 const results = await vscode . commands . executeCommand < vscode . Location [ ] > (
184159 'vscode.executeDefinitionProvider' ,
185160 document . uri ,
@@ -189,10 +164,7 @@ export function registerRazorEndpoints(
189164 return rewriteLocations ( results ) ;
190165 } ) ;
191166
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 ) => {
196168 const results = await vscode . commands . executeCommand < vscode . SignatureHelp > (
197169 'vscode.executeSignatureHelpProvider' ,
198170 document . uri ,
@@ -206,21 +178,15 @@ export function registerRazorEndpoints(
206178 return rewriteSignatureHelp ( results ) ;
207179 } ) ;
208180
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 ) => {
213182 const content = document . getContent ( ) ;
214183 const options = < vscode . FormattingOptions > params . options ;
215184
216185 const response = await FormattingHandler . getHtmlFormattingResult ( document . uri , content , options ) ;
217186 return response ?. edits ;
218187 } ) ;
219188
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 ) => {
224190 const content = document . getContent ( ) ;
225191 const options = < vscode . FormattingOptions > params . options ;
226192
@@ -262,11 +228,21 @@ export function registerRazorEndpoints(
262228 }
263229
264230 // 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 > (
266232 type : RequestType < Params , Result , Error > ,
267- invocation : ( params : Params ) => Promise < Result >
233+ documentManager : HtmlDocumentManager ,
234+ invocation : ( document : HtmlDocument , request : Params ) => Promise < Result >
268235 ) {
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+ } ) ;
270246 }
271247
272248 function registerMethodHandler < Params , Result > ( method : string , invocation : ( params : Params ) => Promise < Result > ) {
0 commit comments