Skip to content

Commit cce655f

Browse files
committed
Log each read config
There's been a couple issue where it is clear from the log of the global configuration that options are being set *somewhere*, but users then have to go searching in all the paths we lookup (which is quite a few). Log each config we read so it's easy to see where the options are coming from.
1 parent 47ca76b commit cce655f

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

Sources/SKOptions/SourceKitLSPOptions.swift

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public import Foundation
1414
public import LanguageServerProtocol
1515
import LanguageServerProtocolExtensions
16-
import SKLogging
16+
package import SKLogging
1717

1818
import struct TSCBasic.AbsolutePath
1919

@@ -500,6 +500,10 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable {
500500
else {
501501
return nil
502502
}
503+
504+
logger.log("Read options from \(path)")
505+
logger.logFullObjectInMultipleLogMessages(header: "Config file options", loggingProxy)
506+
503507
self = decoded
504508
}
505509

@@ -561,3 +565,25 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable {
561565
return experimentalFeatures.contains(feature)
562566
}
563567
}
568+
569+
extension SourceKitLSPOptions {
570+
/// Options proxy to avoid public import of `SKLogging`.
571+
///
572+
/// We can't conform `SourceKitLSPOptions` to `CustomLogStringConvertible` because that would require a public import
573+
/// of `SKLogging`. Instead, define a package type that performs the logging of `SourceKitLSPOptions`.
574+
package struct LoggingProxy: CustomLogStringConvertible {
575+
let options: SourceKitLSPOptions
576+
577+
package var description: String {
578+
options.prettyPrintedJSON
579+
}
580+
581+
package var redactedDescription: String {
582+
options.prettyPrintedRedactedJSON
583+
}
584+
}
585+
586+
package var loggingProxy: LoggingProxy {
587+
LoggingProxy(options: self)
588+
}
589+
}

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ extension SourceKitLSPServer {
917917
)
918918
)
919919
logger.log("Creating workspace at \(workspaceFolder.forLogging)")
920-
logger.logFullObjectInMultipleLogMessages(header: "Options for workspace", options.loggingProxy)
920+
logger.logFullObjectInMultipleLogMessages(header: "Workspace options", options.loggingProxy)
921921

922922
let workspace = await Workspace(
923923
sourceKitLSPServer: self,
@@ -1003,7 +1003,7 @@ extension SourceKitLSPServer {
10031003
}
10041004

10051005
logger.log("Initialized SourceKit-LSP")
1006-
logger.logFullObjectInMultipleLogMessages(header: "SourceKit-LSP Options", options.loggingProxy)
1006+
logger.logFullObjectInMultipleLogMessages(header: "Global options", options.loggingProxy)
10071007

10081008
await workspaceQueue.async { [hooks] in
10091009
if let workspaceFolders = req.workspaceFolders {
@@ -2807,27 +2807,3 @@ fileprivate extension URL {
28072807
return other.pathComponents[0..<self.pathComponents.count] == self.pathComponents[...]
28082808
}
28092809
}
2810-
2811-
extension SourceKitLSPOptions {
2812-
/// We can't conform `SourceKitLSPOptions` to `CustomLogStringConvertible` because that would require a public import
2813-
/// of `SKLogging`. Instead, define an internal type that performs the logging of `SourceKitLSPOptions`.
2814-
struct LoggingProxy: CustomLogStringConvertible {
2815-
let options: SourceKitLSPOptions
2816-
2817-
var description: String {
2818-
options.prettyPrintedJSON
2819-
}
2820-
2821-
var redactedDescription: String {
2822-
options.prettyPrintedRedactedJSON
2823-
}
2824-
}
2825-
2826-
var loggingProxy: LoggingProxy {
2827-
LoggingProxy(options: self)
2828-
}
2829-
2830-
var forLogging: CustomLogStringConvertibleWrapper {
2831-
return self.loggingProxy.forLogging
2832-
}
2833-
}

0 commit comments

Comments
 (0)