Skip to content

Commit da5d854

Browse files
committed
Add an API to get the name of a target from SourceKit-LSP
We will need this API to prepare a target for indexing.
1 parent cb497bd commit da5d854

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Sources/SourceKitLSPAPI/BuildDescription.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import struct PackageGraph.ModulesGraph
2727
public protocol BuildTarget {
2828
var sources: [URL] { get }
2929

30+
/// The name of the target. It should be possible to build a target by passing this name to `swift build --target`
31+
var name: String { get }
32+
3033
/// Whether the target is part of the root package that the user opened or if it's part of a package dependency.
3134
var isPartOfRootPackage: Bool { get }
3235

@@ -46,6 +49,10 @@ private struct WrappedClangTargetBuildDescription: BuildTarget {
4649
return (try? description.compilePaths().map { URL(fileURLWithPath: $0.source.pathString) }) ?? []
4750
}
4851

52+
public var name: String {
53+
return description.clangTarget.name
54+
}
55+
4956
public func compileArguments(for fileURL: URL) throws -> [String] {
5057
let filePath = try resolveSymlinks(try AbsolutePath(validating: fileURL.path))
5158
let commandLine = try description.emitCommandLine(for: filePath)
@@ -63,6 +70,10 @@ private struct WrappedSwiftTargetBuildDescription: BuildTarget {
6370
self.isPartOfRootPackage = isPartOfRootPackage
6471
}
6572

73+
public var name: String {
74+
return description.target.name
75+
}
76+
6677
var sources: [URL] {
6778
return description.sources.map { URL(fileURLWithPath: $0.pathString) }
6879
}

Sources/SourceKitLSPAPI/PluginTargetBuildDescription.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ struct PluginTargetBuildDescription: BuildTarget {
3434
return target.sources.paths.map { URL(fileURLWithPath: $0.pathString) }
3535
}
3636

37+
var name: String {
38+
return target.name
39+
}
40+
3741
func compileArguments(for fileURL: URL) throws -> [String] {
3842
// FIXME: This is very odd and we should clean this up by merging `ManifestLoader` and `DefaultPluginScriptRunner` again.
3943
let loader = ManifestLoader(toolchain: try UserToolchain(swiftSDK: .hostSwiftSDK()))

0 commit comments

Comments
 (0)