Skip to content

Commit b9d1379

Browse files
Exclude third party deps in 'queryTargets' (#37)
* Run SwiftFormat on the file * Ignore third-party dependencies in BazelQueryParser * Refactor enum case patterns in BazelQueryParser error descriptions
1 parent 1cd5d21 commit b9d1379

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Sources/SourceKitBazelBSP/RequestHandlers/BuildTargets/BazelQueryParser.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ enum BazelQueryParser {
5656
/// - `[URI]`: Array of source file URIs associated with the target
5757
static func parseTargetsWithProto(
5858
from targets: [BlazeQuery_Target],
59-
supportedRuleTypes: Set<String>,
59+
supportedRuleTypes _: Set<String>,
6060
rootUri: String,
6161
toolchainPath: String,
6262
buildTestSuffix: String
@@ -69,13 +69,18 @@ enum BazelQueryParser {
6969
continue
7070
}
7171

72+
// Ignore third party deps
73+
guard !target.rule.name.hasPrefix("@") else {
74+
continue
75+
}
76+
7277
let rule = target.rule
7378

7479
let id: URI = try rule.name.toTargetId(rootUri: rootUri, buildTestSuffix: buildTestSuffix)
7580

7681
let baseDirectory: URI = try rule.name.toBaseDirectory(rootUri: rootUri)
7782

78-
var testOnly: Bool = false
83+
var testOnly = false
7984
var deps: [BuildTargetIdentifier] = []
8085
var srcs: [URI] = []
8186
for attr in rule.attribute {
@@ -163,8 +168,8 @@ enum BazelQueryParser {
163168
}
164169

165170
private static func buildTargetData(for toolchainPath: String) throws -> LanguageServerProtocol.LSPAny {
166-
SourceKitBuildTarget(
167-
toolchain: try URI(string: "file://" + toolchainPath)
171+
try SourceKitBuildTarget(
172+
toolchain: URI(string: "file://" + toolchainPath)
168173
).encodeToLSPAny()
169174
}
170175
}
@@ -177,7 +182,7 @@ extension String {
177182
/// file://<path-to-root>/<package-name>___<target-name>_ios<build-test-suffix>
178183
///
179184
func toTargetId(rootUri: String, buildTestSuffix: String) throws -> URI {
180-
let (packageName, targetName) = try self.splitTargetLabel()
185+
let (packageName, targetName) = try splitTargetLabel()
181186

182187
// FIXME: This is assuming everything is iOS code. Will soon update this to handle all platforms.
183188
let path = "file://" + rootUri + "/" + packageName + "___" + targetName + "_ios" + buildTestSuffix
@@ -194,7 +199,7 @@ extension String {
194199
/// file://<path-to-root>/<package-name>
195200
///
196201
func toBaseDirectory(rootUri: String) throws -> URI {
197-
let (packageName, _) = try self.splitTargetLabel()
202+
let (packageName, _) = try splitTargetLabel()
198203

199204
let fileScheme = "file://" + rootUri + "/" + packageName
200205

@@ -207,7 +212,7 @@ extension String {
207212

208213
/// Splits a full Bazel label into a tuple of its package and target names.
209214
func splitTargetLabel() throws -> (packageName: String, targetName: String) {
210-
let components = self.split(separator: ":")
215+
let components = split(separator: ":")
211216

212217
guard components.count == 2 else {
213218
throw BazelTargetParserError.incorrectName

0 commit comments

Comments
 (0)