@@ -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 (
@@ -587,15 +572,7 @@ final class BackgroundIndexingTests: XCTestCase {
587
572
)
588
573
XCTAssertNotEqual ( initialDiagnostics. fullReport? . items, [ ] )
589
574
590
- try " public func foo() {} " . write (
591
- to: try XCTUnwrap ( project. uri ( for: " MyFile.swift " ) . fileURL) ,
592
- atomically: true ,
593
- encoding: . utf8
594
- )
595
-
596
- project. testClient. send (
597
- DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: try project. uri ( for: " MyFile.swift " ) , type: . changed) ] )
598
- )
575
+ try await project. changeFileOnDisk ( " MyFile.swift " , newMarkedContents: " public func foo() {} " )
599
576
600
577
let receivedEmptyDiagnostics = self . expectation ( description: " Received diagnostic refresh request " )
601
578
receivedEmptyDiagnostics. assertForOverFulfill = false
@@ -703,6 +680,8 @@ final class BackgroundIndexingTests: XCTestCase {
703
680
project. testClient. send (
704
681
DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: try project. uri ( for: " LibA.swift " ) , type: . changed) ] )
705
682
)
683
+ // Ensure that we handle the `DidChangeWatchedFilesNotification`.
684
+ try await project. testClient. send ( BarrierRequest ( ) )
706
685
707
686
// Quickly flip through all files. The way the test is designed to work is as follows:
708
687
// - LibB.swift gets opened and prepared. Preparation is simulated to take a long time until both LibC.swift and
@@ -1657,19 +1636,14 @@ final class BackgroundIndexingTests: XCTestCase {
1657
1636
)
1658
1637
XCTAssertNil ( definitionBeforeEdit)
1659
1638
1660
- let libAUri = try project. uri ( for : " LibA.swift " )
1661
- let ( newAMarkers , newAContents ) = DocumentPositions . extract (
1662
- from : """
1639
+ let ( libAUri, newAMarkers ) = try await project. changeFileOnDisk (
1640
+ " LibA.swift " ,
1641
+ newMarkedContents : """
1663
1642
public struct LibA {
1664
1643
public func 2️⃣test() {}
1665
1644
}
1666
1645
"""
1667
1646
)
1668
- try await newAContents. writeWithRetry ( to: XCTUnwrap ( libAUri. fileURL) )
1669
-
1670
- project. testClient. send (
1671
- DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: libAUri, type: . changed) ] )
1672
- )
1673
1647
1674
1648
// Triggering a definition request causes `LibC` to be re-prepared. Repeat the request until LibC has been prepared
1675
1649
// and we get the expected result.
@@ -1718,16 +1692,15 @@ final class BackgroundIndexingTests: XCTestCase {
1718
1692
)
1719
1693
XCTAssertEqual ( completionBeforeEdit. items. map ( \. label) , [ " self " ] )
1720
1694
1721
- let libAUri = try project. uri ( for: " LibA.swift " )
1722
- try await """
1723
- public struct LibA {
1724
- public func test() {}
1725
- }
1726
- """ . writeWithRetry ( to: XCTUnwrap ( libAUri. fileURL) )
1727
-
1728
- project. testClient. send (
1729
- DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: libAUri, type: . changed) ] )
1695
+ try await project. changeFileOnDisk (
1696
+ " LibA.swift " ,
1697
+ newMarkedContents: """
1698
+ public struct LibA {
1699
+ public func test() {}
1700
+ }
1701
+ """
1730
1702
)
1703
+
1731
1704
try await repeatUntilExpectedResult {
1732
1705
let completionAfterEdit = try await project. testClient. send (
1733
1706
CompletionRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 1️⃣ " ] )
@@ -1781,9 +1754,7 @@ final class BackgroundIndexingTests: XCTestCase {
1781
1754
" Pre edit hover content ' \( preEditHoverContent) ' does not contain 'String' "
1782
1755
)
1783
1756
1784
- let libAUri = try project. uri ( for: " LibA.swift " )
1785
- try await " public let myVar: Int " . writeWithRetry ( to: try XCTUnwrap ( libAUri. fileURL) )
1786
- project. testClient. send ( DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: libAUri, type: . changed) ] ) )
1757
+ try await project. changeFileOnDisk ( " LibA.swift " , newMarkedContents: " public let myVar: Int " )
1787
1758
1788
1759
try await repeatUntilExpectedResult {
1789
1760
let postEditHover = try await project. testClient. send (
@@ -2080,22 +2051,22 @@ final class BackgroundIndexingTests: XCTestCase {
2080
2051
)
2081
2052
XCTAssertNil ( hoverWithMissingDependencyDeclaration)
2082
2053
2083
- let manifestUri = try project. uri ( for: " Package.swift " )
2084
- try """
2085
- // swift-tools-version: 5.7
2054
+ try await project. changeFileOnDisk (
2055
+ " Package.swift " ,
2056
+ newMarkedContents: """
2057
+ // swift-tools-version: 5.7
2086
2058
2087
- import PackageDescription
2059
+ import PackageDescription
2088
2060
2089
- let package = Package(
2090
- name: " MyLibrary " ,
2091
- targets: [
2092
- .target(name: " LibA " , swiftSettings: [.define( " ENABLE_FOO " )]),
2093
- .target(name: " LibB " , dependencies: [ " LibA " ]),
2094
- ]
2061
+ let package = Package(
2062
+ name: " MyLibrary " ,
2063
+ targets: [
2064
+ .target(name: " LibA " , swiftSettings: [.define( " ENABLE_FOO " )]),
2065
+ .target(name: " LibB " , dependencies: [ " LibA " ]),
2066
+ ]
2067
+ )
2068
+ """
2095
2069
)
2096
- """ . write ( to: XCTUnwrap ( project. uri ( for: " Package.swift " ) . fileURL) , atomically: true , encoding: . utf8)
2097
-
2098
- project. testClient. send ( DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: manifestUri, type: . changed) ] ) )
2099
2070
2100
2071
try await repeatUntilExpectedResult {
2101
2072
let hoverAfterAddingDependencyDeclaration = try await project. testClient. send (
0 commit comments