11namespace ts . projectSystem {
2- describe ( "unittests:: tsserver:: with project references and error reporting" , ( ) => {
3- const dependecyLocation = `${ projectRoot } /dependency` ;
4- const usageLocation = `${ projectRoot } /usage` ;
2+ export interface GetErrDiagnostics {
3+ file : string | File ;
4+ syntax ?: protocol . Diagnostic [ ] ;
5+ semantic ?: protocol . Diagnostic [ ] ;
6+ suggestion ?: protocol . Diagnostic [ ] ;
7+ }
8+ export interface VerifyGetErrRequestBase {
9+ session : TestSession ;
10+ host : TestServerHost ;
11+ onErrEvent ?: ( ) => void ;
12+ existingTimeouts ?: number ;
13+ }
14+ export interface VerifyGetErrRequest extends VerifyGetErrRequestBase {
15+ expected : readonly GetErrDiagnostics [ ] ;
16+ }
17+ export function verifyGetErrRequest ( request : VerifyGetErrRequest ) {
18+ const { session, expected } = request ;
19+ session . clearMessages ( ) ;
20+ const expectedSequenceId = session . getNextSeq ( ) ;
21+ session . executeCommandSeq < protocol . GeterrRequest > ( {
22+ command : protocol . CommandTypes . Geterr ,
23+ arguments : {
24+ delay : 0 ,
25+ files : expected . map ( f => filePath ( f . file ) )
26+ }
27+ } ) ;
28+ checkAllErrors ( { ...request , expectedSequenceId } ) ;
29+ }
530
6- interface CheckErrorsInFile {
7- session : TestSession ;
8- host : TestServerHost ;
9- expected : GetErrDiagnostics ;
10- expectedSequenceId ?: number ;
31+ export interface CheckAllErrors extends VerifyGetErrRequest {
32+ expectedSequenceId : number ;
33+ }
34+ function checkAllErrors ( { expected, expectedSequenceId, ...rest } : CheckAllErrors ) {
35+ for ( let i = 0 ; i < expected . length ; i ++ ) {
36+ checkErrorsInFile ( {
37+ ...rest ,
38+ expected : expected [ i ] ,
39+ expectedSequenceId : i === expected . length - 1 ? expectedSequenceId : undefined ,
40+ } ) ;
1141 }
12- function checkErrorsInFile ( { session, host, expected : { file, syntax, semantic, suggestion } , expectedSequenceId } : CheckErrorsInFile ) {
42+ }
43+
44+ function filePath ( file : string | File ) {
45+ return isString ( file ) ? file : file . path ;
46+ }
47+ interface CheckErrorsInFile extends VerifyGetErrRequestBase {
48+ expected : GetErrDiagnostics ;
49+ expectedSequenceId ?: number ;
50+ }
51+ function checkErrorsInFile ( {
52+ session, host, onErrEvent, existingTimeouts, expectedSequenceId,
53+ expected : { file, syntax, semantic, suggestion } ,
54+ } : CheckErrorsInFile ) {
55+ onErrEvent = onErrEvent || noop ;
56+ if ( existingTimeouts !== undefined ) {
57+ host . checkTimeoutQueueLength ( existingTimeouts + 1 ) ;
58+ host . runQueuedTimeoutCallbacks ( host . getNextTimeoutId ( ) - 1 ) ;
59+ }
60+ else {
1361 host . checkTimeoutQueueLengthAndRun ( 1 ) ;
14- checkErrorMessage ( session , "syntaxDiag" , { file : file . path , diagnostics : syntax } ) ;
62+ }
63+ if ( syntax ) {
64+ onErrEvent ( ) ;
65+ checkErrorMessage ( session , "syntaxDiag" , { file : filePath ( file ) , diagnostics : syntax } ) ;
66+ }
67+ if ( semantic ) {
1568 session . clearMessages ( ) ;
1669
1770 host . runQueuedImmediateCallbacks ( 1 ) ;
18- checkErrorMessage ( session , "semanticDiag" , { file : file . path , diagnostics : semantic } ) ;
71+ onErrEvent ( ) ;
72+ checkErrorMessage ( session , "semanticDiag" , { file : filePath ( file ) , diagnostics : semantic } ) ;
73+ }
74+ if ( suggestion ) {
1975 session . clearMessages ( ) ;
2076
2177 host . runQueuedImmediateCallbacks ( 1 ) ;
22- checkErrorMessage ( session , "suggestionDiag" , { file : file . path , diagnostics : suggestion } ) ;
23- if ( expectedSequenceId !== undefined ) {
24- checkCompleteEvent ( session , 2 , expectedSequenceId ) ;
25- }
26- session . clearMessages ( ) ;
78+ onErrEvent ( ) ;
79+ checkErrorMessage ( session , "suggestionDiag" , { file : filePath ( file ) , diagnostics : suggestion } ) ;
2780 }
28-
29- interface CheckAllErrors {
30- session : TestSession ;
31- host : TestServerHost ;
32- expected : readonly GetErrDiagnostics [ ] ;
33- expectedSequenceId : number ;
34- }
35- function checkAllErrors ( { session, host, expected, expectedSequenceId } : CheckAllErrors ) {
36- for ( let i = 0 ; i < expected . length ; i ++ ) {
37- checkErrorsInFile ( {
38- session,
39- host,
40- expected : expected [ i ] ,
41- expectedSequenceId : i === expected . length - 1 ? expectedSequenceId : undefined
42- } ) ;
43- }
81+ if ( expectedSequenceId !== undefined ) {
82+ checkCompleteEvent ( session , syntax || semantic || suggestion ? 2 : 1 , expectedSequenceId ) ;
4483 }
84+ session . clearMessages ( ) ;
85+ }
86+
87+ describe ( "unittests:: tsserver:: with project references and error reporting" , ( ) => {
88+ const dependecyLocation = `${ projectRoot } /dependency` ;
89+ const usageLocation = `${ projectRoot } /usage` ;
4590
4691 function verifyErrorsUsingGeterr ( { allFiles, openFiles, expectedGetErr } : VerifyScenario ) {
4792 it ( "verifies the errors in open file" , ( ) => {
4893 const host = createServerHost ( [ ...allFiles ( ) , libFile ] ) ;
4994 const session = createSession ( host , { canUseEvents : true , } ) ;
5095 openFilesForSession ( openFiles ( ) , session ) ;
5196
52- session . clearMessages ( ) ;
53- const expectedSequenceId = session . getNextSeq ( ) ;
54- const expected = expectedGetErr ( ) ;
55- session . executeCommandSeq < protocol . GeterrRequest > ( {
56- command : protocol . CommandTypes . Geterr ,
57- arguments : {
58- delay : 0 ,
59- files : expected . map ( f => f . file . path )
60- }
61- } ) ;
62-
63- checkAllErrors ( { session, host, expected, expectedSequenceId } ) ;
97+ verifyGetErrRequest ( { session, host, expected : expectedGetErr ( ) } ) ;
6498 } ) ;
6599 }
66100
@@ -95,27 +129,27 @@ namespace ts.projectSystem {
95129 const actualSyntax = session . executeCommandSeq < protocol . SyntacticDiagnosticsSyncRequest > ( {
96130 command : protocol . CommandTypes . SyntacticDiagnosticsSync ,
97131 arguments : {
98- file : file . path ,
132+ file : filePath ( file ) ,
99133 projectFileName : project
100134 }
101135 } ) . response as protocol . Diagnostic [ ] ;
102- assert . deepEqual ( actualSyntax , syntax , `Syntax diagnostics for file: ${ file . path } , project: ${ project } ` ) ;
136+ assert . deepEqual ( actualSyntax , syntax , `Syntax diagnostics for file: ${ filePath ( file ) } , project: ${ project } ` ) ;
103137 const actualSemantic = session . executeCommandSeq < protocol . SemanticDiagnosticsSyncRequest > ( {
104138 command : protocol . CommandTypes . SemanticDiagnosticsSync ,
105139 arguments : {
106- file : file . path ,
140+ file : filePath ( file ) ,
107141 projectFileName : project
108142 }
109143 } ) . response as protocol . Diagnostic [ ] ;
110- assert . deepEqual ( actualSemantic , semantic , `Semantic diagnostics for file: ${ file . path } , project: ${ project } ` ) ;
144+ assert . deepEqual ( actualSemantic , semantic , `Semantic diagnostics for file: ${ filePath ( file ) } , project: ${ project } ` ) ;
111145 const actualSuggestion = session . executeCommandSeq < protocol . SuggestionDiagnosticsSyncRequest > ( {
112146 command : protocol . CommandTypes . SuggestionDiagnosticsSync ,
113147 arguments : {
114- file : file . path ,
148+ file : filePath ( file ) ,
115149 projectFileName : project
116150 }
117151 } ) . response as protocol . Diagnostic [ ] ;
118- assert . deepEqual ( actualSuggestion , suggestion , `Suggestion diagnostics for file: ${ file . path } , project: ${ project } ` ) ;
152+ assert . deepEqual ( actualSuggestion , suggestion , `Suggestion diagnostics for file: ${ filePath ( file ) } , project: ${ project } ` ) ;
119153 }
120154 } ) ;
121155 }
@@ -139,12 +173,6 @@ namespace ts.projectSystem {
139173 } ) ;
140174 }
141175
142- interface GetErrDiagnostics {
143- file : File ;
144- syntax : protocol . Diagnostic [ ] ;
145- semantic : protocol . Diagnostic [ ] ;
146- suggestion : protocol . Diagnostic [ ] ;
147- }
148176 interface GetErrForProjectDiagnostics {
149177 project : string ;
150178 errors : readonly GetErrDiagnostics [ ] ;
0 commit comments