Migrate getting the list of all source files to BSP

This commit is contained in:
Alex Hoppen
2024-09-11 12:54:50 -07:00
parent cf47f2c72b
commit c5ba9671f0
15 changed files with 423 additions and 137 deletions

View File

@@ -540,6 +540,41 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
}
}
package func buildTargets(request: BuildTargetsRequest) async throws -> BuildTargetsResponse {
let targets = self.targets.map { (targetId, target) in
var tags: [BuildTargetTag] = [.test]
if target.depth != 1 {
tags.append(.dependency)
}
return BuildTarget(
id: targetId,
displayName: nil,
baseDirectory: nil,
tags: tags,
capabilities: BuildTargetCapabilities(),
// Be conservative with the languages that might be used in the target. SourceKit-LSP doesn't use this property.
languageIds: [.c, .cpp, .objective_c, .objective_cpp, .swift],
// FIXME: (BSP migration) List the target's dependencies
dependencies: []
)
}
return BuildTargetsResponse(targets: targets)
}
package func buildTargetSources(request: BuildTargetSourcesRequest) async throws -> BuildTargetSourcesResponse {
var result: [SourcesItem] = []
for target in request.targets {
guard let swiftPMTarget = self.targets[target] else {
continue
}
let sources = swiftPMTarget.buildTarget.sources.map {
SourceItem(uri: DocumentURI($0), kind: .file, generated: false)
}
result.append(SourcesItem(target: target, sources: sources))
}
return BuildTargetSourcesResponse(items: result)
}
package func sourceKitOptions(request: SourceKitOptionsRequest) async throws -> SourceKitOptionsResponse? {
guard let url = request.textDocument.uri.fileURL, let path = try? AbsolutePath(validating: url.path) else {
// We can't determine build settings for non-file URIs.