4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import * as vscode from 'vscode' ;
7
- import { DocumentDiagnosticReport , DocumentDiagnosticParams , RequestType } from 'vscode-languageserver-protocol' ;
7
+ import { DocumentDiagnosticParams , DocumentDiagnosticReport , RequestType } from 'vscode-languageserver-protocol' ;
8
8
import { RazorLanguageServerClient } from '../razorLanguageServerClient' ;
9
9
import { RazorDocumentManager } from '../document/razorDocumentManager' ;
10
10
import { UriConverter } from '../../../lsptoolshost/utils/uriConverter' ;
@@ -13,14 +13,15 @@ import { RazorLanguageFeatureBase } from '../razorLanguageFeatureBase';
13
13
import { RazorDocumentSynchronizer } from '../document/razorDocumentSynchronizer' ;
14
14
import { RazorLogger } from '../razorLogger' ;
15
15
import { roslynPullDiagnosticCommand } from '../../../lsptoolshost/razor/razorCommands' ;
16
+ import { SerializableTextDocumentIdentifierAndVersion } from '../simplify/serializableTextDocumentIdentifierAndVersion' ;
16
17
17
18
export class RazorDiagnosticHandler extends RazorLanguageFeatureBase {
18
19
private static readonly razorPullDiagnosticsCommand = 'razor/csharpPullDiagnostics' ;
19
- private diagnosticRequestType : RequestType < DocumentDiagnosticParams , DocumentDiagnosticReport , any > =
20
+ private diagnosticRequestType : RequestType < DelegatedDiagnosticParams , DocumentDiagnosticReport , any > =
20
21
new RequestType ( RazorDiagnosticHandler . razorPullDiagnosticsCommand ) ;
21
22
22
23
constructor (
23
- documentSynchronizer : RazorDocumentSynchronizer ,
24
+ protected readonly documentSynchronizer : RazorDocumentSynchronizer ,
24
25
protected readonly serverClient : RazorLanguageServerClient ,
25
26
protected readonly serviceClient : RazorLanguageServiceClient ,
26
27
protected readonly documentManager : RazorDocumentManager ,
@@ -31,31 +32,55 @@ export class RazorDiagnosticHandler extends RazorLanguageFeatureBase {
31
32
32
33
public async register ( ) {
33
34
await this . serverClient . onRequestWithParams <
34
- DocumentDiagnosticParams ,
35
+ DelegatedDiagnosticParams ,
35
36
DocumentDiagnosticReport | undefined ,
36
37
any
37
- > ( this . diagnosticRequestType , async ( request : DocumentDiagnosticParams , token : vscode . CancellationToken ) =>
38
+ > ( this . diagnosticRequestType , async ( request : DelegatedDiagnosticParams , token : vscode . CancellationToken ) =>
38
39
this . getDiagnostic ( request , token )
39
40
) ;
40
41
}
41
42
42
43
private async getDiagnostic (
43
- request : DocumentDiagnosticParams ,
44
- _ : vscode . CancellationToken
44
+ request : DelegatedDiagnosticParams ,
45
+ token : vscode . CancellationToken
45
46
) : Promise < DocumentDiagnosticReport | undefined > {
46
47
if ( ! this . documentManager . roslynActivated ) {
47
48
return undefined ;
48
49
}
49
50
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 ) ;
51
53
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
+
52
66
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
+
54
74
const response : DocumentDiagnosticReport = await vscode . commands . executeCommand (
55
75
roslynPullDiagnosticCommand ,
56
- request
76
+ roslynRequest
57
77
) ;
58
78
59
79
return response ;
60
80
}
61
81
}
82
+
83
+ interface DelegatedDiagnosticParams {
84
+ identifier : SerializableTextDocumentIdentifierAndVersion ;
85
+ correlationId : string ;
86
+ }
0 commit comments