@@ -430,24 +430,14 @@ final class BackgroundIndexingTests: XCTestCase {
430
430
)
431
431
XCTAssertEqual ( callsBeforeEdit, [ ] )
432
432
433
- let ( otherFilePositions, otherFileMarkedContents) = DocumentPositions . extract (
434
- from: """
433
+ let ( otherFileUri, otherFilePositions) = try await project. changeFileOnDisk (
434
+ " MyOtherFile.swift " ,
435
+ newMarkedContents: """
435
436
func 2️⃣bar() {
436
437
3️⃣foo()
437
438
}
438
439
"""
439
440
)
440
-
441
- let otherFileUri = try project. uri ( for: " MyOtherFile.swift " )
442
- let otherFileUrl = try XCTUnwrap ( otherFileUri. fileURL)
443
-
444
- try otherFileMarkedContents. write (
445
- to: otherFileUrl,
446
- atomically: true ,
447
- encoding: . utf8
448
- )
449
-
450
- project. testClient. send ( DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: otherFileUri, type: . changed) ] ) )
451
441
try await project. testClient. send ( PollIndexRequest ( ) )
452
442
453
443
let callsAfterEdit = try await project. testClient. send (
@@ -498,21 +488,16 @@ final class BackgroundIndexingTests: XCTestCase {
498
488
)
499
489
XCTAssertEqual ( callsBeforeEdit, [ ] )
500
490
501
- let ( newPositions, headerNewMarkedContents) = DocumentPositions . extract (
502
- from: """
491
+ let ( _, newPositions) = try await project. changeFileOnDisk (
492
+ " Header.h " ,
493
+ newMarkedContents: """
503
494
void someFunc();
504
495
505
496
void 2️⃣test() {
506
497
3️⃣someFunc();
507
498
};
508
499
"""
509
500
)
510
-
511
- // clangd might have Header.h open, which prevents us from updating it. Keep retrying until we get a successful
512
- // write. This matches what a user would do.
513
- try await headerNewMarkedContents. writeWithRetry ( to: try XCTUnwrap ( uri. fileURL) )
514
-
515
- project. testClient. send ( DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: uri, type: . changed) ] ) )
516
501
try await project. testClient. send ( PollIndexRequest ( ) )
517
502
518
503
let callsAfterEdit = try await project. testClient. send (
@@ -584,15 +569,7 @@ final class BackgroundIndexingTests: XCTestCase {
584
569
)
585
570
XCTAssertNotEqual ( initialDiagnostics. fullReport? . items, [ ] )
586
571
587
- try " public func foo() {} " . write (
588
- to: try XCTUnwrap ( project. uri ( for: " MyFile.swift " ) . fileURL) ,
589
- atomically: true ,
590
- encoding: . utf8
591
- )
592
-
593
- project. testClient. send (
594
- DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: try project. uri ( for: " MyFile.swift " ) , type: . changed) ] )
595
- )
572
+ try await project. changeFileOnDisk ( " MyFile.swift " , newMarkedContents: " public func foo() {} " )
596
573
597
574
let receivedEmptyDiagnostics = self . expectation ( description: " Received diagnostic refresh request " )
598
575
receivedEmptyDiagnostics. assertForOverFulfill = false
@@ -700,6 +677,8 @@ final class BackgroundIndexingTests: XCTestCase {
700
677
project. testClient. send (
701
678
DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: try project. uri ( for: " LibA.swift " ) , type: . changed) ] )
702
679
)
680
+ // Ensure that we handle the `DidChangeWatchedFilesNotification`.
681
+ try await project. testClient. send ( BarrierRequest ( ) )
703
682
704
683
// Quickly flip through all files. The way the test is designed to work is as follows:
705
684
// - LibB.swift gets opened and prepared. Preparation is simulated to take a long time until both LibC.swift and
@@ -1654,19 +1633,14 @@ final class BackgroundIndexingTests: XCTestCase {
1654
1633
)
1655
1634
XCTAssertNil ( definitionBeforeEdit)
1656
1635
1657
- let libAUri = try project. uri ( for : " LibA.swift " )
1658
- let ( newAMarkers , newAContents ) = DocumentPositions . extract (
1659
- from : """
1636
+ let ( libAUri, newAMarkers ) = try await project. changeFileOnDisk (
1637
+ " LibA.swift " ,
1638
+ newMarkedContents : """
1660
1639
public struct LibA {
1661
1640
public func 2️⃣test() {}
1662
1641
}
1663
1642
"""
1664
1643
)
1665
- try await newAContents. writeWithRetry ( to: XCTUnwrap ( libAUri. fileURL) )
1666
-
1667
- project. testClient. send (
1668
- DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: libAUri, type: . changed) ] )
1669
- )
1670
1644
1671
1645
// Triggering a definition request causes `LibC` to be re-prepared. Repeat the request until LibC has been prepared
1672
1646
// and we get the expected result.
@@ -1715,16 +1689,15 @@ final class BackgroundIndexingTests: XCTestCase {
1715
1689
)
1716
1690
XCTAssertEqual ( completionBeforeEdit. items. map ( \. label) , [ " self " ] )
1717
1691
1718
- let libAUri = try project. uri ( for: " LibA.swift " )
1719
- try await """
1720
- public struct LibA {
1721
- public func test() {}
1722
- }
1723
- """ . writeWithRetry ( to: XCTUnwrap ( libAUri. fileURL) )
1724
-
1725
- project. testClient. send (
1726
- DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: libAUri, type: . changed) ] )
1692
+ try await project. changeFileOnDisk (
1693
+ " LibA.swift " ,
1694
+ newMarkedContents: """
1695
+ public struct LibA {
1696
+ public func test() {}
1697
+ }
1698
+ """
1727
1699
)
1700
+
1728
1701
try await repeatUntilExpectedResult {
1729
1702
let completionAfterEdit = try await project. testClient. send (
1730
1703
CompletionRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 1️⃣ " ] )
@@ -1778,9 +1751,7 @@ final class BackgroundIndexingTests: XCTestCase {
1778
1751
" Pre edit hover content ' \( preEditHoverContent) ' does not contain 'String' "
1779
1752
)
1780
1753
1781
- let libAUri = try project. uri ( for: " LibA.swift " )
1782
- try await " public let myVar: Int " . writeWithRetry ( to: try XCTUnwrap ( libAUri. fileURL) )
1783
- project. testClient. send ( DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: libAUri, type: . changed) ] ) )
1754
+ try await project. changeFileOnDisk ( " LibA.swift " , newMarkedContents: " public let myVar: Int " )
1784
1755
1785
1756
try await repeatUntilExpectedResult {
1786
1757
let postEditHover = try await project. testClient. send (
@@ -2076,22 +2047,22 @@ final class BackgroundIndexingTests: XCTestCase {
2076
2047
)
2077
2048
XCTAssertNil ( hoverWithMissingDependencyDeclaration)
2078
2049
2079
- let manifestUri = try project. uri ( for: " Package.swift " )
2080
- try """
2081
- // swift-tools-version: 5.7
2050
+ try await project. changeFileOnDisk (
2051
+ " Package.swift " ,
2052
+ newMarkedContents: """
2053
+ // swift-tools-version: 5.7
2082
2054
2083
- import PackageDescription
2055
+ import PackageDescription
2084
2056
2085
- let package = Package(
2086
- name: " MyLibrary " ,
2087
- targets: [
2088
- .target(name: " LibA " , swiftSettings: [.define( " ENABLE_FOO " )]),
2089
- .target(name: " LibB " , dependencies: [ " LibA " ]),
2090
- ]
2057
+ let package = Package(
2058
+ name: " MyLibrary " ,
2059
+ targets: [
2060
+ .target(name: " LibA " , swiftSettings: [.define( " ENABLE_FOO " )]),
2061
+ .target(name: " LibB " , dependencies: [ " LibA " ]),
2062
+ ]
2063
+ )
2064
+ """
2091
2065
)
2092
- """ . write ( to: XCTUnwrap ( project. uri ( for: " Package.swift " ) . fileURL) , atomically: true , encoding: . utf8)
2093
-
2094
- project. testClient. send ( DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: manifestUri, type: . changed) ] ) )
2095
2066
2096
2067
try await repeatUntilExpectedResult {
2097
2068
let hoverAfterAddingDependencyDeclaration = try await project. testClient. send (
0 commit comments