Skip to content

Commit 0e061c5

Browse files
authored
Merge pull request #2363 from ahoppen/preparation-status-trailing-slash
Fix issue that caused the target preparation status to not be cleared when workspace root did not have trailing slash
2 parents c1414a7 + 05b290e commit 0e061c5

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

Sources/BuildServerIntegration/SwiftPMBuildServer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,9 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
844844
else {
845845
return false
846846
}
847-
return url.deletingLastPathComponent() == self.projectRoot
847+
// Compare the URLs as `DocumentURI`, which is a little more lenient to declare equality, eg. it considers paths
848+
// equivalent even `url.deletingLastPathComponent()` has a trailing slash while `self.projectRoot` does not.
849+
return DocumentURI(url.deletingLastPathComponent()) == DocumentURI(self.projectRoot)
848850
}
849851

850852
/// An event is relevant if it modifies a file that matches one of the file rules used by the SwiftPM workspace.

Tests/SourceKitLSPTests/SwiftPMIntegrationTests.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,4 +697,69 @@ final class SwiftPMIntegrationTests: SourceKitLSPTestCase {
697697
return diagnosticsAfterUpdate.fullReport?.items.map(\.message) == ["MY_FLAG set"]
698698
}
699699
}
700+
701+
func testClearPreparationStatusWhenPackageManifestIsModifiedAndPackageIsOpenedWithoutTrailingSlash() async throws {
702+
let project = try await SwiftPMTestProject(
703+
files: [
704+
"MyLibrary/MyLibrary.swift": """
705+
#if MY_FLAG
706+
public func foo() -> String { "" }
707+
#else
708+
public func foo() -> Int { "" }
709+
#endif
710+
""",
711+
"MyExecutable/MyExecutable.swift": """
712+
import MyLibrary
713+
714+
let 1️⃣x = foo()
715+
""",
716+
],
717+
manifest: """
718+
// swift-tools-version: 5.7
719+
720+
import PackageDescription
721+
722+
let package = Package(
723+
name: "MyLibrary",
724+
targets: [
725+
.target(name: "MyLibrary"),
726+
.executableTarget(name: "MyExecutable", dependencies: ["MyLibrary"])
727+
]
728+
)
729+
""",
730+
workspaces: {
731+
[WorkspaceFolder(uri: DocumentURI(try URL(filePath: $0.filePath, directoryHint: .notDirectory)))]
732+
},
733+
enableBackgroundIndexing: true
734+
)
735+
let (uri, positions) = try project.openDocument("MyExecutable.swift")
736+
let preEditHoverResponse = try await project.testClient.send(
737+
HoverRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"])
738+
)
739+
assertContains(try XCTUnwrap(preEditHoverResponse?.contents.markupContent?.value), "let x: Int")
740+
741+
try await project.changeFileOnDisk(
742+
"Package.swift",
743+
newMarkedContents: """
744+
// swift-tools-version: 5.7
745+
746+
import PackageDescription
747+
748+
let package = Package(
749+
name: "MyLibrary",
750+
targets: [
751+
.target(name: "MyLibrary", swiftSettings: [.define("MY_FLAG")]),
752+
.executableTarget(name: "MyExecutable", dependencies: ["MyLibrary"])
753+
]
754+
)
755+
"""
756+
)
757+
758+
try await repeatUntilExpectedResult {
759+
let postEditHoverResponse = try await project.testClient.send(
760+
HoverRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"])
761+
)
762+
return try XCTUnwrap(postEditHoverResponse?.contents.markupContent?.value).contains("let x: String")
763+
}
764+
}
700765
}

0 commit comments

Comments
 (0)