Skip to content

Commit e3b64f9

Browse files
committed
[SourceKitLSPAPI] Add a way to retrieve headers from a `BuildTarget
1 parent 13b861c commit e3b64f9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Sources/SourceKitLSPAPI/BuildDescription.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ internal import class PackageModel.UserToolchain
2929
public typealias BuildTriple = PackageGraph.BuildTriple
3030

3131
public protocol BuildTarget {
32+
/// Source files in the target
3233
var sources: [URL] { get }
3334

35+
/// Header files in the target
36+
var headers: [URL] { get }
37+
3438
/// The name of the target. It should be possible to build a target by passing this name to `swift build --target`
3539
var name: String { get }
3640

@@ -52,7 +56,14 @@ private struct WrappedClangTargetBuildDescription: BuildTarget {
5256
}
5357

5458
public var sources: [URL] {
55-
return (try? description.compilePaths().map { URL(fileURLWithPath: $0.source.pathString) }) ?? []
59+
guard let compilePaths = try? description.compilePaths() else {
60+
return []
61+
}
62+
return compilePaths.map(\.source.asURL)
63+
}
64+
65+
public var headers: [URL] {
66+
return description.clangTarget.headers.map(\.asURL)
5667
}
5768

5869
public var name: String {
@@ -92,6 +103,8 @@ private struct WrappedSwiftTargetBuildDescription: BuildTarget {
92103
return description.sources.map { URL(fileURLWithPath: $0.pathString) }
93104
}
94105

106+
var headers: [URL] { [] }
107+
95108
func compileArguments(for fileURL: URL) throws -> [String] {
96109
// Note: we ignore the `fileURL` here as the expectation is that we get a command line for the entire target
97110
// in case of Swift.

Sources/SourceKitLSPAPI/PluginTargetBuildDescription.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ struct PluginTargetBuildDescription: BuildTarget {
3939
return target.sources.paths.map { URL(fileURLWithPath: $0.pathString) }
4040
}
4141

42+
var headers: [URL] { [] }
43+
4244
var name: String {
4345
return target.name
4446
}

0 commit comments

Comments
 (0)