Skip to content

Commit f825d9c

Browse files
authored
Merge pull request #1453 from ahoppen/semantic-functionality-with-build-error-in-low-level-module
Add test to check that we get semantic functionality even if a dependency module fails to prepare
2 parents e687fe4 + dfb7b46 commit f825d9c

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,27 @@ public actor SkipUnless {
265265
}
266266
}
267267

268+
public static func swiftPMSupportsExperimentalPrepareForIndexing(
269+
file: StaticString = #filePath,
270+
line: UInt = #line
271+
) async throws {
272+
struct NoSwiftInToolchain: Error {}
273+
274+
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
275+
guard let swift = await ToolchainRegistry.forTesting.default?.swift else {
276+
throw NoSwiftInToolchain()
277+
}
278+
279+
let process = Process(args: swift.pathString, "build", "--help-hidden")
280+
try process.launch()
281+
let result = try await process.waitUntilExit()
282+
guard let output = String(bytes: try result.output.get(), encoding: .utf8) else {
283+
return false
284+
}
285+
return output.contains("--experimental-prepare-for-indexing")
286+
}
287+
}
288+
268289
/// A long test is a test that takes longer than 1-2s to execute.
269290
public static func longTestsEnabled() throws {
270291
if let value = ProcessInfo.processInfo.environment["SKIP_LONG_TESTS"], value == "1" || value == "YES" {

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,6 @@ final class BackgroundIndexingTests: XCTestCase {
10011001
}
10021002

10031003
func testLibraryUsedByExecutableTargetAndPackagePlugin() async throws {
1004-
try await SkipUnless.swiftpmStoresModulesInSubdirectory()
10051004
let project = try await SwiftPMTestProject(
10061005
files: [
10071006
"Lib/MyFile.swift": """
@@ -1022,8 +1021,6 @@ final class BackgroundIndexingTests: XCTestCase {
10221021
""",
10231022
],
10241023
manifest: """
1025-
// swift-tools-version: 5.7
1026-
import PackageDescription
10271024
let package = Package(
10281025
name: "MyLibrary",
10291026
targets: [
@@ -1049,4 +1046,51 @@ final class BackgroundIndexingTests: XCTestCase {
10491046
)
10501047
XCTAssertEqual(definition, .locations([try project.location(from: "1️⃣", to: "1️⃣", in: "MyFile.swift")]))
10511048
}
1049+
1050+
func testCrossModuleFunctionalityEvenIfLowLevelModuleHasErrors() async throws {
1051+
try await SkipUnless.swiftPMSupportsExperimentalPrepareForIndexing()
1052+
var serverOptions = SourceKitLSPServer.Options.testDefault
1053+
serverOptions.experimentalFeatures.insert(.swiftpmPrepareForIndexing)
1054+
let project = try await SwiftPMTestProject(
1055+
files: [
1056+
"LibA/LibA.swift": """
1057+
public func test() -> Invalid {
1058+
return ""
1059+
}
1060+
""",
1061+
"LibB/LibB.swift": """
1062+
import LibA
1063+
1064+
public func 1️⃣libBTest() -> Int {
1065+
return libATest()
1066+
}
1067+
""",
1068+
"MyExec/MyExec.swift": """
1069+
import LibB
1070+
1071+
func test() -> Int {
1072+
return 2️⃣libBTest()
1073+
}
1074+
""",
1075+
],
1076+
manifest: """
1077+
let package = Package(
1078+
name: "MyLibrary",
1079+
targets: [
1080+
.target(name: "LibA"),
1081+
.target(name: "LibB", dependencies: ["LibA"]),
1082+
.executableTarget(name: "MyExec", dependencies: ["LibB"]),
1083+
]
1084+
)
1085+
""",
1086+
serverOptions: serverOptions,
1087+
enableBackgroundIndexing: true
1088+
)
1089+
1090+
let (uri, positions) = try project.openDocument("MyExec.swift")
1091+
let response = try await project.testClient.send(
1092+
DefinitionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["2️⃣"])
1093+
)
1094+
XCTAssertEqual(response, .locations([try project.location(from: "1️⃣", to: "1️⃣", in: "LibB.swift")]))
1095+
}
10521096
}

0 commit comments

Comments
 (0)