@@ -61,7 +61,7 @@ fnErr();
61
61
interface CheckAllErrors {
62
62
session : TestSession ;
63
63
host : TestServerHost ;
64
- expected : ReadonlyArray < GetErrDiagnostics > ;
64
+ expected : readonly GetErrDiagnostics [ ] ;
65
65
expectedSequenceId : number ;
66
66
}
67
67
function checkAllErrors ( { session, host, expected, expectedSequenceId } : CheckAllErrors ) {
@@ -118,6 +118,40 @@ fnErr();
118
118
} ) ;
119
119
}
120
120
121
+ function verifyErrorsUsingSyncMethods ( { openFiles, expectedSyncDiagnostics } : VerifyScenario ) {
122
+ it ( "verifies the errors using sync commands" , ( ) => {
123
+ const host = createServerHost ( [ dependencyTs , dependencyConfig , usageTs , usageConfig , libFile ] ) ;
124
+ const session = createSession ( host ) ;
125
+ openFilesForSession ( openFiles ( ) , session ) ;
126
+ for ( const { file, project, syntax, semantic, suggestion } of expectedSyncDiagnostics ( ) ) {
127
+ const actualSyntax = session . executeCommandSeq < protocol . SyntacticDiagnosticsSyncRequest > ( {
128
+ command : protocol . CommandTypes . SyntacticDiagnosticsSync ,
129
+ arguments : {
130
+ file : file . path ,
131
+ projectFileName : project
132
+ }
133
+ } ) . response as protocol . Diagnostic [ ] ;
134
+ assert . deepEqual ( actualSyntax , syntax , `Syntax diagnostics for file: ${ file . path } , project: ${ project } ` ) ;
135
+ const actualSemantic = session . executeCommandSeq < protocol . SemanticDiagnosticsSyncRequest > ( {
136
+ command : protocol . CommandTypes . SemanticDiagnosticsSync ,
137
+ arguments : {
138
+ file : file . path ,
139
+ projectFileName : project
140
+ }
141
+ } ) . response as protocol . Diagnostic [ ] ;
142
+ assert . deepEqual ( actualSemantic , semantic , `Semantic diagnostics for file: ${ file . path } , project: ${ project } ` ) ;
143
+ const actualSuggestion = session . executeCommandSeq < protocol . SuggestionDiagnosticsSyncRequest > ( {
144
+ command : protocol . CommandTypes . SuggestionDiagnosticsSync ,
145
+ arguments : {
146
+ file : file . path ,
147
+ projectFileName : project
148
+ }
149
+ } ) . response as protocol . Diagnostic [ ] ;
150
+ assert . deepEqual ( actualSuggestion , suggestion , `Suggestion diagnostics for file: ${ file . path } , project: ${ project } ` ) ;
151
+ }
152
+ } ) ;
153
+ }
154
+
121
155
interface GetErrDiagnostics {
122
156
file : File ;
123
157
syntax : protocol . Diagnostic [ ] ;
@@ -126,16 +160,21 @@ fnErr();
126
160
}
127
161
interface GetErrForProjectDiagnostics {
128
162
project : string ;
129
- errors : ReadonlyArray < GetErrDiagnostics > ;
163
+ errors : readonly GetErrDiagnostics [ ] ;
164
+ }
165
+ interface SyncDiagnostics extends GetErrDiagnostics {
166
+ project ?: string ;
130
167
}
131
168
interface VerifyScenario {
132
- openFiles : ( ) => ReadonlyArray < File > ;
133
- expectedGetErr : ( ) => ReadonlyArray < GetErrDiagnostics > ;
134
- expectedGetErrForProject : ( ) => ReadonlyArray < GetErrForProjectDiagnostics > ;
169
+ openFiles : ( ) => readonly File [ ] ;
170
+ expectedGetErr : ( ) => readonly GetErrDiagnostics [ ] ;
171
+ expectedGetErrForProject : ( ) => readonly GetErrForProjectDiagnostics [ ] ;
172
+ expectedSyncDiagnostics : ( ) => readonly SyncDiagnostics [ ] ;
135
173
}
136
174
function verifyScenario ( scenario : VerifyScenario ) {
137
175
verifyErrorsUsingGeterr ( scenario ) ;
138
176
verifyErrorsUsingGeterrForProject ( scenario ) ;
177
+ verifyErrorsUsingSyncMethods ( scenario ) ;
139
178
}
140
179
141
180
function emptyDiagnostics ( file : File ) : GetErrDiagnostics {
@@ -169,13 +208,13 @@ fnErr();
169
208
file : dependencyTs ,
170
209
syntax : emptyArray ,
171
210
semantic : [
172
- createDiagnostic (
173
- { line : 6 , offset : 12 } ,
174
- { line : 6 , offset : 13 } ,
175
- Diagnostics . Type_0_is_not_assignable_to_type_1 ,
176
- [ "10" , "string" ] ,
177
- "error" ,
178
- )
211
+ createDiagnostic (
212
+ { line : 6 , offset : 12 } ,
213
+ { line : 6 , offset : 13 } ,
214
+ Diagnostics . Type_0_is_not_assignable_to_type_1 ,
215
+ [ "10" , "string" ] ,
216
+ "error" ,
217
+ )
179
218
] ,
180
219
suggestion : emptyArray
181
220
} ;
@@ -200,6 +239,10 @@ fnErr();
200
239
} ;
201
240
}
202
241
242
+ function syncDiagnostics ( diagnostics : GetErrDiagnostics , project : string ) : SyncDiagnostics {
243
+ return { project, ...diagnostics } ;
244
+ }
245
+
203
246
describe ( "when dependency project is not open" , ( ) => {
204
247
verifyScenario ( {
205
248
openFiles : ( ) => [ usageTs ] ,
@@ -215,7 +258,15 @@ fnErr();
215
258
usageDiagnostics ( )
216
259
]
217
260
}
218
- ]
261
+ ] ,
262
+ expectedSyncDiagnostics : ( ) => [
263
+ // Without project
264
+ usageDiagnostics ( ) ,
265
+ emptyDiagnostics ( dependencyTs ) ,
266
+ // With project
267
+ syncDiagnostics ( usageDiagnostics ( ) , usageConfig . path ) ,
268
+ syncDiagnostics ( emptyDiagnostics ( dependencyTs ) , usageConfig . path ) ,
269
+ ] ,
219
270
} ) ;
220
271
} ) ;
221
272
@@ -229,7 +280,16 @@ fnErr();
229
280
expectedGetErrForProject : ( ) => [
230
281
usageProjectDiagnostics ( ) ,
231
282
dependencyProjectDiagnostics ( )
232
- ]
283
+ ] ,
284
+ expectedSyncDiagnostics : ( ) => [
285
+ // Without project
286
+ usageDiagnostics ( ) ,
287
+ dependencyDiagnostics ( ) ,
288
+ // With project
289
+ syncDiagnostics ( usageDiagnostics ( ) , usageConfig . path ) ,
290
+ syncDiagnostics ( emptyDiagnostics ( dependencyTs ) , usageConfig . path ) ,
291
+ syncDiagnostics ( dependencyDiagnostics ( ) , dependencyConfig . path ) ,
292
+ ] ,
233
293
} ) ;
234
294
} ) ;
235
295
} ) ;
0 commit comments