44 *--------------------------------------------------------------------------------------------*/
55
66import * as vscode from 'vscode' ;
7- import { DocumentDiagnosticReport , DocumentDiagnosticParams , RequestType } from 'vscode-languageserver-protocol' ;
7+ import { DocumentDiagnosticParams , DocumentDiagnosticReport , RequestType } from 'vscode-languageserver-protocol' ;
88import { RazorLanguageServerClient } from '../razorLanguageServerClient' ;
99import { RazorDocumentManager } from '../document/razorDocumentManager' ;
1010import { UriConverter } from '../../../lsptoolshost/utils/uriConverter' ;
@@ -13,14 +13,15 @@ import { RazorLanguageFeatureBase } from '../razorLanguageFeatureBase';
1313import { RazorDocumentSynchronizer } from '../document/razorDocumentSynchronizer' ;
1414import { RazorLogger } from '../razorLogger' ;
1515import { roslynPullDiagnosticCommand } from '../../../lsptoolshost/razor/razorCommands' ;
16+ import { SerializableTextDocumentIdentifierAndVersion } from '../simplify/serializableTextDocumentIdentifierAndVersion' ;
1617
1718export class RazorDiagnosticHandler extends RazorLanguageFeatureBase {
1819 private static readonly razorPullDiagnosticsCommand = 'razor/csharpPullDiagnostics' ;
19- private diagnosticRequestType : RequestType < DocumentDiagnosticParams , DocumentDiagnosticReport , any > =
20+ private diagnosticRequestType : RequestType < DelegatedDiagnosticParams , DocumentDiagnosticReport , any > =
2021 new RequestType ( RazorDiagnosticHandler . razorPullDiagnosticsCommand ) ;
2122
2223 constructor (
23- documentSynchronizer : RazorDocumentSynchronizer ,
24+ protected readonly documentSynchronizer : RazorDocumentSynchronizer ,
2425 protected readonly serverClient : RazorLanguageServerClient ,
2526 protected readonly serviceClient : RazorLanguageServiceClient ,
2627 protected readonly documentManager : RazorDocumentManager ,
@@ -31,31 +32,55 @@ export class RazorDiagnosticHandler extends RazorLanguageFeatureBase {
3132
3233 public async register ( ) {
3334 await this . serverClient . onRequestWithParams <
34- DocumentDiagnosticParams ,
35+ DelegatedDiagnosticParams ,
3536 DocumentDiagnosticReport | undefined ,
3637 any
37- > ( this . diagnosticRequestType , async ( request : DocumentDiagnosticParams , token : vscode . CancellationToken ) =>
38+ > ( this . diagnosticRequestType , async ( request : DelegatedDiagnosticParams , token : vscode . CancellationToken ) =>
3839 this . getDiagnostic ( request , token )
3940 ) ;
4041 }
4142
4243 private async getDiagnostic (
43- request : DocumentDiagnosticParams ,
44- _ : vscode . CancellationToken
44+ request : DelegatedDiagnosticParams ,
45+ token : vscode . CancellationToken
4546 ) : Promise < DocumentDiagnosticReport | undefined > {
4647 if ( ! this . documentManager . roslynActivated ) {
4748 return undefined ;
4849 }
4950
50- const razorDocumentUri = vscode . Uri . parse ( request . textDocument . uri , true ) ;
51+ const razorDocumentUri = vscode . Uri . parse ( request . identifier . textDocumentIdentifier . uri , true ) ;
52+ const textDocument = await vscode . workspace . openTextDocument ( razorDocumentUri ) ;
5153 const razorDocument = await this . documentManager . getDocument ( razorDocumentUri ) ;
54+
55+ const synchronized = await this . documentSynchronizer . trySynchronizeProjectedDocument (
56+ textDocument ,
57+ razorDocument . csharpDocument ,
58+ request . identifier . version ,
59+ token
60+ ) ;
61+
62+ if ( ! synchronized ) {
63+ return undefined ;
64+ }
65+
5266 const virtualCSharpUri = razorDocument . csharpDocument . uri ;
53- request . textDocument . uri = UriConverter . serialize ( virtualCSharpUri ) ;
67+
68+ const roslynRequest : DocumentDiagnosticParams = {
69+ textDocument : {
70+ uri : UriConverter . serialize ( virtualCSharpUri ) ,
71+ } ,
72+ } ;
73+
5474 const response : DocumentDiagnosticReport = await vscode . commands . executeCommand (
5575 roslynPullDiagnosticCommand ,
56- request
76+ roslynRequest
5777 ) ;
5878
5979 return response ;
6080 }
6181}
82+
83+ interface DelegatedDiagnosticParams {
84+ identifier : SerializableTextDocumentIdentifierAndVersion ;
85+ correlationId : string ;
86+ }
0 commit comments