1
1
namespace 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
+ }
5
30
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
+ } ) ;
11
41
}
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 {
13
61
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 ) {
15
68
session . clearMessages ( ) ;
16
69
17
70
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 ) {
19
75
session . clearMessages ( ) ;
20
76
21
77
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 } ) ;
27
80
}
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 ) ;
44
83
}
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` ;
45
90
46
91
function verifyErrorsUsingGeterr ( { allFiles, openFiles, expectedGetErr } : VerifyScenario ) {
47
92
it ( "verifies the errors in open file" , ( ) => {
48
93
const host = createServerHost ( [ ...allFiles ( ) , libFile ] ) ;
49
94
const session = createSession ( host , { canUseEvents : true , } ) ;
50
95
openFilesForSession ( openFiles ( ) , session ) ;
51
96
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 ( ) } ) ;
64
98
} ) ;
65
99
}
66
100
@@ -95,27 +129,27 @@ namespace ts.projectSystem {
95
129
const actualSyntax = session . executeCommandSeq < protocol . SyntacticDiagnosticsSyncRequest > ( {
96
130
command : protocol . CommandTypes . SyntacticDiagnosticsSync ,
97
131
arguments : {
98
- file : file . path ,
132
+ file : filePath ( file ) ,
99
133
projectFileName : project
100
134
}
101
135
} ) . 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 } ` ) ;
103
137
const actualSemantic = session . executeCommandSeq < protocol . SemanticDiagnosticsSyncRequest > ( {
104
138
command : protocol . CommandTypes . SemanticDiagnosticsSync ,
105
139
arguments : {
106
- file : file . path ,
140
+ file : filePath ( file ) ,
107
141
projectFileName : project
108
142
}
109
143
} ) . 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 } ` ) ;
111
145
const actualSuggestion = session . executeCommandSeq < protocol . SuggestionDiagnosticsSyncRequest > ( {
112
146
command : protocol . CommandTypes . SuggestionDiagnosticsSync ,
113
147
arguments : {
114
- file : file . path ,
148
+ file : filePath ( file ) ,
115
149
projectFileName : project
116
150
}
117
151
} ) . 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 } ` ) ;
119
153
}
120
154
} ) ;
121
155
}
@@ -139,12 +173,6 @@ namespace ts.projectSystem {
139
173
} ) ;
140
174
}
141
175
142
- interface GetErrDiagnostics {
143
- file : File ;
144
- syntax : protocol . Diagnostic [ ] ;
145
- semantic : protocol . Diagnostic [ ] ;
146
- suggestion : protocol . Diagnostic [ ] ;
147
- }
148
176
interface GetErrForProjectDiagnostics {
149
177
project : string ;
150
178
errors : readonly GetErrDiagnostics [ ] ;
0 commit comments