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