@@ -38,12 +38,12 @@ extension CommandRunner {
3838// MARK: Bazel-related helpers
3939
4040extension CommandRunner {
41- func bazel( baseConfig: BaseServerConfig , rootUri: String , cmd: String ) throws -> String {
41+ func bazel( baseConfig: BaseServerConfig , rootUri: String , cmd: String ) throws -> some ContentRepresentable {
4242 try run ( baseConfig. bazelWrapper + " " + cmd, cwd: rootUri)
4343 }
4444
4545 /// A regular bazel command, but at this BSP's special output base and taking into account the special index flags.
46- func bazelIndexAction( initializedConfig: InitializedServerConfig , cmd: String ) throws -> String {
46+ func bazelIndexAction( initializedConfig: InitializedServerConfig , cmd: String ) throws -> some ContentRepresentable {
4747 return try bazelIndexAction (
4848 baseConfig: initializedConfig. baseConfig,
4949 outputBase: initializedConfig. outputBase,
@@ -52,25 +52,13 @@ extension CommandRunner {
5252 )
5353 }
5454
55- /// A bazel action query command, but at this BSP's special output base and taking into account the special index flags.
56- func bazelActionQuery( initializedConfig: InitializedServerConfig , cmd: String ) throws -> Data {
57- let baseCommand = [
58- initializedConfig. baseConfig. bazelWrapper,
59- " --output_base= \( initializedConfig. outputBase) " ,
60- cmd,
61- ]
62- let additionalFlags = initializedConfig. baseConfig. indexFlags
63- let command = ( baseCommand + additionalFlags) . joined ( separator: " " )
64- return try run ( command, cwd: initializedConfig. rootUri)
65- }
66-
6755 /// A regular bazel command, but at this BSP's special output base and taking into account the special index flags.
6856 func bazelIndexAction(
6957 baseConfig: BaseServerConfig ,
7058 outputBase: String ,
7159 cmd: String ,
7260 rootUri: String ,
73- ) throws -> String {
61+ ) throws -> some ContentRepresentable {
7462 let indexFlags = baseConfig. indexFlags
7563 let additionalFlags : String
7664 if indexFlags. isEmpty {
@@ -82,3 +70,30 @@ extension CommandRunner {
8270 return try bazel ( baseConfig: baseConfig, rootUri: rootUri, cmd: cmd)
8371 }
8472}
73+
74+ // Define a protocol that both String and Data types can conform to
75+ protocol ContentRepresentable {
76+ var asData : Data { get }
77+ var asString : String { get }
78+ }
79+
80+ extension String : ContentRepresentable {
81+ var asData : Data {
82+ Data ( self . utf8)
83+ }
84+
85+ var asString : String {
86+ return self
87+ }
88+ }
89+
90+ extension Data : ContentRepresentable {
91+ var asData : Data {
92+ self
93+ }
94+
95+ var asString : String {
96+ let str = String ( data: self , encoding: . utf8) ?? " "
97+ return str. trimmingCharacters ( in: . whitespacesAndNewlines)
98+ }
99+ }
0 commit comments