Skip to content

Commit 26ba6bb

Browse files
authored
Add dependency_rules_to_discover to the bazel setup, minor fixes (#137)
1 parent 0bd5351 commit 26ba6bb

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

Example/HelloWorld/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,11 @@ setup_sourcekit_bsp(
250250
files_to_watch = [
251251
"HelloWorld/**/*.swift",
252252
"HelloWorld/**/*.h",
253-
"HelloWorld/**/*.m"
253+
"HelloWorld/**/*.m",
254+
"HelloWorld/**/*.mm",
255+
"HelloWorld/**/*.c",
256+
"HelloWorld/**/*.hpp",
257+
"HelloWorld/**/*.cpp"
254258
],
255259
index_flags = [
256260
"config=index_build",

Sources/SourceKitBazelBSP/RequestHandlers/BuildTargets/BazelTargetQuerierParser.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,19 +296,28 @@ final class BazelTargetQuerierParserImpl: BazelTargetQuerierParser {
296296
depLabelToUriMap: depLabelToUriMap
297297
)
298298

299-
// These settings serve no particular purpose today. They are ignored by sourcekit-lsp.
299+
// AFAIK these settings serve no particular purpose today and are ignored by sourcekit-lsp.
300300
let capabilities = BuildTargetCapabilities(
301301
canCompile: true,
302302
canTest: false,
303303
canRun: false,
304304
canDebug: false
305305
)
306306

307+
let isExternal = rule.name.hasPrefix("@")
308+
let tags: [BuildTargetTag] = {
309+
var tags: [BuildTargetTag] = [.library]
310+
if isExternal {
311+
tags.append(.dependency)
312+
}
313+
return tags
314+
}()
315+
307316
let buildTarget = BuildTarget(
308317
id: id,
309318
displayName: rule.name,
310319
baseDirectory: baseDirectory,
311-
tags: [.library],
320+
tags: tags,
312321
capabilities: capabilities,
313322
languageIds: [ruleType.language],
314323
dependencies: deps,

Sources/sourcekit-bazel-bsp/Commands/Serve.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ struct Serve: ParsableCommand {
6868
@Option(
6969
parsing: .singleValue,
7070
help:
71-
"A target pattern to exclude when discovering top-level targets. Can be specified multiple times."
71+
"A target pattern to exclude when discovering top-level targets. Can be specified multiple times. Wildcards are supported (e.g. //foo/...)."
7272
)
7373
var topLevelTargetToExclude: [String] = []
7474

7575
@Option(
7676
parsing: .singleValue,
7777
help:
78-
"A target pattern to exclude when discovering dependency targets. Can be specified multiple times."
78+
"A target pattern to exclude when discovering dependency targets. Can be specified multiple times. Wildcards are supported (e.g. //foo/...)."
7979
)
8080
var dependencyTargetToExclude: [String] = []
8181

rules/setup_sourcekit_bsp.bzl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def _setup_sourcekit_bsp_impl(ctx):
2222
for top_level_rule in ctx.attr.top_level_rules_to_discover:
2323
bsp_config_argv.append("--top-level-rule-to-discover")
2424
bsp_config_argv.append(top_level_rule)
25+
for dependency_rule in ctx.attr.dependency_rules_to_discover:
26+
bsp_config_argv.append("--dependency-rule-to-discover")
27+
bsp_config_argv.append(dependency_rule)
2528
for target in ctx.attr.top_level_targets_to_exclude:
2629
bsp_config_argv.append("--top-level-target-to-exclude")
2730
bsp_config_argv.append(target)
@@ -123,12 +126,16 @@ setup_sourcekit_bsp = rule(
123126
doc = "A list of top-level rule types to discover targets for (e.g. 'ios_application', 'ios_unit_test'). If not specified, all supported top-level rule types will be used for target discovery.",
124127
default = [],
125128
),
129+
"dependency_rules_to_discover": attr.string_list(
130+
doc = "A list of dependency rule types to discover targets for (e.g. 'swift_library', 'objc_library', 'cc_library'). If not specified, all supported dependency rule types will be used for target discovery.",
131+
default = [],
132+
),
126133
"top_level_targets_to_exclude": attr.string_list(
127-
doc = "A list of target patterns to exclude from top-level targets in the cquery.",
134+
doc = "A list of target patterns to exclude from top-level targets in the cquery. Wildcards are supported (e.g. //foo/...).",
128135
default = [],
129136
),
130137
"dependency_targets_to_exclude": attr.string_list(
131-
doc = "A list of target patterns to exclude from dependency targets in the cquery.",
138+
doc = "A list of target patterns to exclude from dependency targets in the cquery. Wildcards are supported (e.g. //foo/...).",
132139
default = [],
133140
),
134141
"index_build_batch_size": attr.int(

0 commit comments

Comments
 (0)