@@ -153,7 +153,7 @@ final class SwiftInterfaceTests: XCTestCase {
153
153
public init() {}
154
154
}
155
155
""" ,
156
- " Exec/main.swift " : " import 1️⃣MyLibrary "
156
+ " Exec/main.swift " : " import 1️⃣MyLibrary " ,
157
157
] ,
158
158
manifest: """
159
159
let package = Package(
@@ -196,13 +196,21 @@ final class SwiftInterfaceTests: XCTestCase {
196
196
func testSemanticFunctionalityInGeneratedInterface( ) async throws {
197
197
let project = try await SwiftPMTestProject (
198
198
files: [
199
- " MyLibrary/MyLibrary.swift " : " public struct Lib { public func foo() -> String {} } " ,
200
- " Exec/main.swift " : " import 1️⃣MyLibrary "
199
+ " MyLibrary/MyLibrary.swift " : """
200
+ public struct Lib {
201
+ public func foo() -> String {}
202
+ public init() {}
203
+ }
204
+ """ ,
205
+ " Exec/main.swift " : " import 1️⃣MyLibrary " ,
201
206
] ,
202
207
manifest: """
203
208
let package = Package(
204
209
name: " MyLibrary " ,
205
- targets: [.target(name: " MyLibrary " ), .executableTarget(name: " Exec " , dependencies: [ " MyLibrary " ])]
210
+ targets: [
211
+ .target(name: " MyLibrary " ),
212
+ .executableTarget(name: " Exec " , dependencies: [ " MyLibrary " ])
213
+ ]
206
214
)
207
215
""" ,
208
216
capabilities: ClientCapabilities ( experimental: [
@@ -217,21 +225,28 @@ final class SwiftInterfaceTests: XCTestCase {
217
225
)
218
226
let referenceDocumentUri = try XCTUnwrap ( response? . locations? . only) . uri
219
227
let referenceDocument = try await project. testClient. send ( GetReferenceDocumentRequest ( uri: referenceDocumentUri) )
220
-
228
+
221
229
// Test hover functionality in the interface
222
- if let stringIndex = referenceDocument. content. firstRange ( of: " -> String " ) {
223
- let ( line, column) = LineTable ( referenceDocument. content)
224
- . lineAndUTF16ColumnOf ( referenceDocument. content. index ( stringIndex. lowerBound, offsetBy: 3 ) )
225
- project. testClient. send (
226
- DidOpenTextDocumentNotification (
227
- textDocument: TextDocumentItem ( uri: referenceDocumentUri, language: . swift, version: 0 , text: referenceDocument. content)
230
+ let stringIndex = try XCTUnwrap ( referenceDocument. content. firstRange ( of: " -> String " ) )
231
+ let ( line, column) = LineTable ( referenceDocument. content)
232
+ . lineAndUTF16ColumnOf ( referenceDocument. content. index ( stringIndex. lowerBound, offsetBy: 3 ) )
233
+ project. testClient. send (
234
+ DidOpenTextDocumentNotification (
235
+ textDocument: TextDocumentItem (
236
+ uri: referenceDocumentUri,
237
+ language: . swift,
238
+ version: 0 ,
239
+ text: referenceDocument. content
228
240
)
229
241
)
230
- let hover = try await project. testClient. send (
231
- HoverRequest ( textDocument: TextDocumentIdentifier ( referenceDocumentUri) , position: Position ( line: line, utf16index: column) )
242
+ )
243
+ let hover = try await project. testClient. send (
244
+ HoverRequest (
245
+ textDocument: TextDocumentIdentifier ( referenceDocumentUri) ,
246
+ position: Position ( line: line, utf16index: column)
232
247
)
233
- XCTAssertNotNil ( hover )
234
- }
248
+ )
249
+ XCTAssertNotNil ( hover )
235
250
}
236
251
237
252
func testJumpToSynthesizedExtensionMethodInSystemModuleWithoutIndex( ) async throws {
@@ -313,13 +328,11 @@ final class SwiftInterfaceTests: XCTestCase {
313
328
GetReferenceDocumentRequest . method: . dictionary( [ " supported " : . bool( true ) ] )
314
329
] )
315
330
)
316
- let uri = DocumentURI ( for: . swiftinterface )
331
+ let uri = DocumentURI ( for: . swift )
317
332
318
333
let positions = testClient. openDocument (
319
334
"""
320
- func test(x: 1️⃣String) {
321
- let a: 2️⃣Int = 5
322
- }
335
+ func test(x: 1️⃣String) {}
323
336
""" ,
324
337
uri: uri
325
338
)
@@ -331,25 +344,13 @@ final class SwiftInterfaceTests: XCTestCase {
331
344
let interfaceUri = try XCTUnwrap ( stringDefinition? . locations? . only? . uri)
332
345
let interfaceContents = try await testClient. send ( GetReferenceDocumentRequest ( uri: interfaceUri) )
333
346
// Open the interface document
334
- testClient. send (
335
- DidOpenTextDocumentNotification (
336
- textDocument: TextDocumentItem (
337
- uri: interfaceUri,
338
- language: . swift,
339
- version: 0 ,
340
- text: interfaceContents. content
341
- )
342
- )
343
- )
347
+ testClient. openDocument ( interfaceContents. content, uri: interfaceUri, language: . swift)
344
348
345
349
// Find a symbol within the interface (e.g., "init" method in String)
346
- guard let initRange = interfaceContents. content. range ( of: " public init() " ) else {
347
- XCTFail ( " Could not find 'public init()' in String interface " )
348
- return
349
- }
350
+ let initRange = try XCTUnwrap ( interfaceContents. content. range ( of: " public init() " ) )
350
351
let lineTable = LineTable ( interfaceContents. content)
351
352
let ( line, column) = lineTable. lineAndUTF16ColumnOf ( initRange. lowerBound)
352
- let initPosition = Position ( line: line, utf16index: column + 7 ) // Position on "init"
353
+ let initPosition = Position ( line: line, utf16index: column + 7 ) // Position on "init"
353
354
354
355
// Test definition request within the interface
355
356
let internalDefinition = try await testClient. send (
@@ -359,18 +360,9 @@ final class SwiftInterfaceTests: XCTestCase {
359
360
)
360
361
)
361
362
362
- // The definition should either:
363
- // 1. Return a position within the same interface (internal navigation)
364
- // 2. Return the same position if it's already at the definition
365
- // 3. Return nil if no definition is available
366
- if let location = internalDefinition? . locations? . first {
367
- // If we get a location, it should be in the same interface or a related one
368
- XCTAssertTrue (
369
- location. uri. pseudoPath. hasSuffix ( " .swiftinterface " ) ||
370
- location. uri == interfaceUri,
371
- " Internal navigation should stay within interface files, got: \( location. uri. pseudoPath) "
372
- )
373
- }
363
+ let location = try XCTUnwrap ( internalDefinition? . locations? . first)
364
+ XCTAssertTrue ( location. uri. pseudoPath. hasSuffix ( " .swiftinterface " ) )
365
+ XCTAssertTrue ( location. uri == interfaceUri)
374
366
}
375
367
376
368
func testFoundationImportNavigation( ) async throws {
@@ -385,7 +377,8 @@ final class SwiftInterfaceTests: XCTestCase {
385
377
"""
386
378
import 1️⃣Foundation
387
379
""" ,
388
- uri: uri
380
+ uri: uri,
381
+ language: . swift
389
382
)
390
383
391
384
// Test navigation to Foundation module
@@ -394,11 +387,8 @@ final class SwiftInterfaceTests: XCTestCase {
394
387
)
395
388
let foundationLocation = try XCTUnwrap ( foundationDefinition? . locations? . only)
396
389
// Verify it's a swiftinterface file (can be either file:// or sourcekit-lsp:// scheme)
397
- XCTAssertTrue (
398
- foundationLocation. uri. pseudoPath. hasSuffix ( " .swiftinterface " ) ||
399
- ( foundationLocation. uri. scheme == " sourcekit-lsp " &&
400
- foundationLocation. uri. pseudoPath. contains ( " Foundation.swiftinterface " ) )
401
- )
390
+ XCTAssertTrue ( foundationLocation. uri. scheme == " sourcekit-lsp " )
391
+ XCTAssertTrue ( foundationLocation. uri. pseudoPath. hasSuffix ( " Foundation.swiftinterface " ) )
402
392
}
403
393
404
394
func testFoundationSubmoduleNavigation( ) async throws {
@@ -419,23 +409,18 @@ final class SwiftInterfaceTests: XCTestCase {
419
409
let foundationDefinition = try await testClient. send (
420
410
DefinitionRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 1️⃣ " ] )
421
411
)
422
- if let foundationLocation = foundationDefinition? . locations? . only {
423
- XCTAssertTrue (
424
- foundationLocation. uri. pseudoPath. contains ( " Foundation.swiftinterface " ) ||
425
- foundationLocation. uri. scheme == " sourcekit-lsp "
426
- )
427
- }
412
+ let foundationLocation = try XCTUnwrap ( foundationDefinition? . locations? . only)
413
+ XCTAssertTrue ( foundationLocation. uri. pseudoPath. contains ( " Foundation.swiftinterface " ) )
414
+ XCTAssertTrue ( foundationLocation. uri. scheme == " sourcekit-lsp " )
415
+
428
416
// Test navigation to NSAffineTransform
429
417
let transformDefinition = try await testClient. send (
430
418
DefinitionRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 2️⃣ " ] )
431
419
)
432
- if let transformLocation = transformDefinition? . locations? . only {
433
- // Verify we can identify this as a swiftinterface file
434
- XCTAssertTrue (
435
- transformLocation. uri. pseudoPath. contains ( " Foundation.NSAffineTransform.swiftinterface " ) ||
436
- transformLocation. uri. scheme == " sourcekit-lsp "
437
- )
438
- }
420
+ let transformLocation = try XCTUnwrap ( transformDefinition? . locations? . only)
421
+ // Verify we can identify this as a swiftinterface file
422
+ XCTAssertTrue ( transformLocation. uri. pseudoPath. contains ( " Foundation.NSAffineTransform.swiftinterface " ) )
423
+ XCTAssertTrue ( transformLocation. uri. scheme == " sourcekit-lsp " )
439
424
}
440
425
}
441
426
0 commit comments