Skip to content

Commit 444ce41

Browse files
committed
Log all options when opening a SourceKit-LSP workspace
Previously, OSLog was truncating these options after ~1000 bytes, which left out valuable information about the setup.
1 parent 32613f2 commit 444ce41

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

Sources/SKLogging/SplitLogMessage.swift

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
///
1818
/// - Note: This will only split along newline boundary. If a single line is longer than `maxChunkSize`, it won't be
1919
/// split. This is fine for compiler argument splitting since a single argument is rarely longer than 800 characters.
20-
package func splitLongMultilineMessage(message: String, maxChunkSize: Int = 800) -> [String] {
20+
package func splitLongMultilineMessage(message: String) -> [String] {
21+
let maxChunkSize = 800
2122
var chunks: [String] = []
2223
for line in message.split(separator: "\n", omittingEmptySubsequences: false) {
2324
if let lastChunk = chunks.last, lastChunk.utf8.count + line.utf8.count < maxChunkSize {
@@ -34,3 +35,34 @@ package func splitLongMultilineMessage(message: String, maxChunkSize: Int = 800)
3435
}
3536
return chunks
3637
}
38+
39+
extension Logger {
40+
/// Implementation detail of `logFullObjectInMultipleLogMessages`
41+
private struct LoggableChunk: CustomLogStringConvertible {
42+
var description: String
43+
var redactedDescription: String
44+
}
45+
46+
package func logFullObjectInMultipleLogMessages(
47+
level: LogLevel = .default,
48+
header: StaticString,
49+
_ subject: some CustomLogStringConvertible
50+
) {
51+
let chunks = splitLongMultilineMessage(message: subject.description)
52+
let redactedChunks = splitLongMultilineMessage(message: subject.redactedDescription)
53+
let maxChunkCount = max(chunks.count, redactedChunks.count)
54+
for i in 0..<maxChunkCount {
55+
let loggableChunk = LoggableChunk(
56+
description: i < chunks.count ? chunks[i] : "",
57+
redactedDescription: i < redactedChunks.count ? redactedChunks[i] : ""
58+
)
59+
self.log(
60+
level: level,
61+
"""
62+
\(header, privacy: .public) (\(i + 1)/\(maxChunkCount))
63+
\(loggableChunk.forLogging)
64+
"""
65+
)
66+
}
67+
}
68+
}

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ extension SourceKitLSPServer {
842842
)
843843
)
844844
logger.log("Creating workspace at \(workspaceFolder.forLogging) with options: \(options.forLogging)")
845+
logger.logFullObjectInMultipleLogMessages(header: "Options for workspace", options)
845846

846847
let workspace = await Workspace(
847848
sourceKitLSPServer: self,
@@ -923,7 +924,8 @@ extension SourceKitLSPServer {
923924
override: orLog("Parsing SourceKitLSPOptions", { try SourceKitLSPOptions(fromLSPAny: req.initializationOptions) })
924925
)
925926

926-
logger.log("Initialized SourceKit-LSP with options: \(self.options.forLogging)")
927+
logger.log("Initialized SourceKit-LSP")
928+
logger.logFullObjectInMultipleLogMessages(header: "SourceKit-LSP Options", self.options)
927929

928930
await workspaceQueue.async { [testHooks] in
929931
if let workspaceFolders = req.workspaceFolders {

0 commit comments

Comments
 (0)