@@ -246,4 +246,116 @@ class DefinitionTests: XCTestCase {
246
246
] )
247
247
)
248
248
}
249
+
250
+ func testDefinitionOfClassBetweenModulesObjC( ) async throws {
251
+ let ws = try await SwiftPMTestWorkspace (
252
+ files: [
253
+ " LibA/include/LibA.h " : """
254
+ @interface 1️⃣LibAClass2️⃣
255
+ - (void)doSomething;
256
+ @end
257
+ """ ,
258
+ " LibB/include/dummy.h " : " " ,
259
+ " LibB/LibB.m " : """
260
+ @import LibA;
261
+ @interface Test
262
+ @end
263
+
264
+ @implementation Test
265
+ - (void)test:(3️⃣LibAClass *)libAClass {
266
+ [libAClass doSomething];
267
+ }
268
+ @end
269
+ """ ,
270
+ ] ,
271
+ manifest: """
272
+ // swift-tools-version: 5.7
273
+
274
+ import PackageDescription
275
+
276
+ let package = Package(
277
+ name: " MyLibrary " ,
278
+ targets: [
279
+ .target(name: " LibA " ),
280
+ .target(name: " LibB " , dependencies: [ " LibA " ]),
281
+ ]
282
+ )
283
+ """
284
+ )
285
+ let ( uri, positions) = try ws. openDocument ( " LibB.m " )
286
+ let response = try await ws. testClient. send (
287
+ DefinitionRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 3️⃣ " ] )
288
+ )
289
+
290
+ guard case . locations( let locations) = response else {
291
+ XCTFail ( " Expected locations response " )
292
+ return
293
+ }
294
+
295
+ XCTAssertEqual ( locations. count, 1 )
296
+ let location = try XCTUnwrap ( locations. first)
297
+ XCTAssertEqual (
298
+ location,
299
+ Location (
300
+ uri: try ws. uri ( for: " LibA.h " ) ,
301
+ range: try ws. position ( of: " 1️⃣ " , in: " LibA.h " ) ..< ws. position ( of: " 2️⃣ " , in: " LibA.h " )
302
+ )
303
+ )
304
+ }
305
+
306
+ func testDefinitionOfMethodBetweenModulesObjC( ) async throws {
307
+ let ws = try await SwiftPMTestWorkspace (
308
+ files: [
309
+ " LibA/include/LibA.h " : """
310
+ @interface LibAClass
311
+ - (void)1️⃣doSomething2️⃣;
312
+ @end
313
+ """ ,
314
+ " LibB/include/dummy.h " : " " ,
315
+ " LibB/LibB.m " : """
316
+ @import LibA;
317
+ @interface Test
318
+ @end
319
+
320
+ @implementation Test
321
+ - (void)test:(LibAClass *)libAClass {
322
+ [libAClass 3️⃣doSomething];
323
+ }
324
+ @end
325
+ """ ,
326
+ ] ,
327
+ manifest: """
328
+ // swift-tools-version: 5.7
329
+
330
+ import PackageDescription
331
+
332
+ let package = Package(
333
+ name: " MyLibrary " ,
334
+ targets: [
335
+ .target(name: " LibA " ),
336
+ .target(name: " LibB " , dependencies: [ " LibA " ]),
337
+ ]
338
+ )
339
+ """
340
+ )
341
+ let ( uri, positions) = try ws. openDocument ( " LibB.m " )
342
+ let response = try await ws. testClient. send (
343
+ DefinitionRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 3️⃣ " ] )
344
+ )
345
+
346
+ guard case . locations( let locations) = response else {
347
+ XCTFail ( " Expected locations response " )
348
+ return
349
+ }
350
+
351
+ XCTAssertEqual ( locations. count, 1 )
352
+ let location = try XCTUnwrap ( locations. first)
353
+ XCTAssertEqual (
354
+ location,
355
+ Location (
356
+ uri: try ws. uri ( for: " LibA.h " ) ,
357
+ range: try ws. position ( of: " 1️⃣ " , in: " LibA.h " ) ..< ws. position ( of: " 2️⃣ " , in: " LibA.h " )
358
+ )
359
+ )
360
+ }
249
361
}
0 commit comments