@@ -61,7 +61,7 @@ fnErr();
6161 interface CheckAllErrors {
6262 session : TestSession ;
6363 host : TestServerHost ;
64- expected : ReadonlyArray < GetErrDiagnostics > ;
64+ expected : readonly GetErrDiagnostics [ ] ;
6565 expectedSequenceId : number ;
6666 }
6767 function checkAllErrors ( { session, host, expected, expectedSequenceId } : CheckAllErrors ) {
@@ -118,6 +118,40 @@ fnErr();
118118 } ) ;
119119 }
120120
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+
121155 interface GetErrDiagnostics {
122156 file : File ;
123157 syntax : protocol . Diagnostic [ ] ;
@@ -126,16 +160,21 @@ fnErr();
126160 }
127161 interface GetErrForProjectDiagnostics {
128162 project : string ;
129- errors : ReadonlyArray < GetErrDiagnostics > ;
163+ errors : readonly GetErrDiagnostics [ ] ;
164+ }
165+ interface SyncDiagnostics extends GetErrDiagnostics {
166+ project ?: string ;
130167 }
131168 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 [ ] ;
135173 }
136174 function verifyScenario ( scenario : VerifyScenario ) {
137175 verifyErrorsUsingGeterr ( scenario ) ;
138176 verifyErrorsUsingGeterrForProject ( scenario ) ;
177+ verifyErrorsUsingSyncMethods ( scenario ) ;
139178 }
140179
141180 function emptyDiagnostics ( file : File ) : GetErrDiagnostics {
@@ -169,13 +208,13 @@ fnErr();
169208 file : dependencyTs ,
170209 syntax : emptyArray ,
171210 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+ )
179218 ] ,
180219 suggestion : emptyArray
181220 } ;
@@ -200,6 +239,10 @@ fnErr();
200239 } ;
201240 }
202241
242+ function syncDiagnostics ( diagnostics : GetErrDiagnostics , project : string ) : SyncDiagnostics {
243+ return { project, ...diagnostics } ;
244+ }
245+
203246 describe ( "when dependency project is not open" , ( ) => {
204247 verifyScenario ( {
205248 openFiles : ( ) => [ usageTs ] ,
@@ -215,7 +258,15 @@ fnErr();
215258 usageDiagnostics ( )
216259 ]
217260 }
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+ ] ,
219270 } ) ;
220271 } ) ;
221272
@@ -229,7 +280,16 @@ fnErr();
229280 expectedGetErrForProject : ( ) => [
230281 usageProjectDiagnostics ( ) ,
231282 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+ ] ,
233293 } ) ;
234294 } ) ;
235295 } ) ;
0 commit comments