@@ -164,6 +164,104 @@ final class LocalSwiftTests: XCTestCase {
164
164
} )
165
165
}
166
166
167
+ func testCrossFileDiagnostics( ) {
168
+ let urlA = URL ( fileURLWithPath: " /a.swift " )
169
+ let urlB = URL ( fileURLWithPath: " /b.swift " )
170
+
171
+ sk. allowUnexpectedNotification = false
172
+
173
+ sk. sendNoteSync ( DidOpenTextDocument ( textDocument: TextDocumentItem (
174
+ url: urlA, language: . swift, version: 12 ,
175
+ text: """
176
+ _ = foo()
177
+ """
178
+ ) ) , { ( note: Notification < PublishDiagnostics > ) in
179
+ log ( " Received diagnostics for open - syntactic " )
180
+ // 1 = semantic update finished already
181
+ // 0 = only syntactic
182
+ XCTAssertLessThanOrEqual ( note. params. diagnostics. count, 1 )
183
+ } , { ( note: Notification < PublishDiagnostics > ) in
184
+ log ( " Received diagnostics for open - semantic " )
185
+ XCTAssertEqual ( note. params. diagnostics. count, 1 )
186
+ XCTAssertEqual (
187
+ note. params. diagnostics. first? . range. lowerBound,
188
+ Position ( line: 0 , utf16index: 4 ) )
189
+ } )
190
+
191
+ sk. sendNoteSync ( DidOpenTextDocument ( textDocument: TextDocumentItem (
192
+ url: urlB, language: . swift, version: 12 ,
193
+ text: """
194
+ _ = bar()
195
+ """
196
+ ) ) , { ( note: Notification < PublishDiagnostics > ) in
197
+ log ( " Received diagnostics for open - syntactic " )
198
+ // 1 = semantic update finished already
199
+ // 0 = only syntactic
200
+ XCTAssertLessThanOrEqual ( note. params. diagnostics. count, 1 )
201
+ } , { ( note: Notification < PublishDiagnostics > ) in
202
+ log ( " Received diagnostics for open - semantic " )
203
+ XCTAssertEqual ( note. params. diagnostics. count, 1 )
204
+ XCTAssertEqual (
205
+ note. params. diagnostics. first? . range. lowerBound,
206
+ Position ( line: 0 , utf16index: 4 ) )
207
+ } )
208
+
209
+ sk. sendNoteSync ( DidChangeTextDocument ( textDocument: . init( urlA, version: 13 ) , contentChanges: [
210
+ . init( range: nil , text: " _ = foo() \n " )
211
+ ] ) , { ( note: Notification < PublishDiagnostics > ) in
212
+ log ( " Received diagnostics for edit 1 - syntactic " )
213
+ XCTAssertEqual ( note. params. diagnostics. count, 1 )
214
+ } , { ( note: Notification < PublishDiagnostics > ) in
215
+ log ( " Received diagnostics for edit 1 - semantic " )
216
+ XCTAssertEqual ( note. params. diagnostics. count, 1 )
217
+ } )
218
+ }
219
+
220
+ func testDiagnosticsReopen( ) {
221
+ let urlA = URL ( fileURLWithPath: " /a.swift " )
222
+ sk. allowUnexpectedNotification = false
223
+
224
+ sk. sendNoteSync ( DidOpenTextDocument ( textDocument: TextDocumentItem (
225
+ url: urlA, language: . swift, version: 12 ,
226
+ text: """
227
+ _ = foo()
228
+ """
229
+ ) ) , { ( note: Notification < PublishDiagnostics > ) in
230
+ log ( " Received diagnostics for open - syntactic " )
231
+ // 1 = semantic update finished already
232
+ // 0 = only syntactic
233
+ XCTAssertLessThanOrEqual ( note. params. diagnostics. count, 1 )
234
+ } , { ( note: Notification < PublishDiagnostics > ) in
235
+ log ( " Received diagnostics for open - semantic " )
236
+ XCTAssertEqual ( note. params. diagnostics. count, 1 )
237
+ XCTAssertEqual (
238
+ note. params. diagnostics. first? . range. lowerBound,
239
+ Position ( line: 0 , utf16index: 4 ) )
240
+ } )
241
+
242
+ sk. send ( DidCloseTextDocument ( textDocument: . init( urlA) ) )
243
+
244
+ sk. sendNoteSync ( DidOpenTextDocument ( textDocument: TextDocumentItem (
245
+ url: urlA, language: . swift, version: 13 ,
246
+ text: """
247
+ var
248
+ """
249
+ ) ) , { ( note: Notification < PublishDiagnostics > ) in
250
+ log ( " Received diagnostics for open - syntactic " )
251
+ // 1 = syntactic, no cached semantic diagnostic from previous version
252
+ XCTAssertEqual ( note. params. diagnostics. count, 1 )
253
+ XCTAssertEqual (
254
+ note. params. diagnostics. first? . range. lowerBound,
255
+ Position ( line: 0 , utf16index: 3 ) )
256
+ } , { ( note: Notification < PublishDiagnostics > ) in
257
+ log ( " Received diagnostics for open - semantic " )
258
+ XCTAssertEqual ( note. params. diagnostics. count, 1 )
259
+ XCTAssertEqual (
260
+ note. params. diagnostics. first? . range. lowerBound,
261
+ Position ( line: 0 , utf16index: 3 ) )
262
+ } )
263
+ }
264
+
167
265
func testXMLToMarkdownDeclaration( ) {
168
266
XCTAssertEqual ( try ! xmlDocumentationToMarkdown ( """
169
267
<Declaration>func foo(_ bar: <Type usr= " fake " >Baz</Type>)</Declaration>
0 commit comments