From cce655ff921f609f7a51aa2731dda315748b700b Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Fri, 29 Aug 2025 13:59:55 -0700 Subject: [PATCH] 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. --- Sources/SKOptions/SourceKitLSPOptions.swift | 28 ++++++++++++++++++- Sources/SourceKitLSP/SourceKitLSPServer.swift | 28 ++----------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Sources/SKOptions/SourceKitLSPOptions.swift b/Sources/SKOptions/SourceKitLSPOptions.swift index dbf07658a..484d8cf16 100644 --- a/Sources/SKOptions/SourceKitLSPOptions.swift +++ b/Sources/SKOptions/SourceKitLSPOptions.swift @@ -13,7 +13,7 @@ public import Foundation public import LanguageServerProtocol import LanguageServerProtocolExtensions -import SKLogging +package import SKLogging import struct TSCBasic.AbsolutePath @@ -500,6 +500,10 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable { else { return nil } + + logger.log("Read options from \(path)") + logger.logFullObjectInMultipleLogMessages(header: "Config file options", loggingProxy) + self = decoded } @@ -561,3 +565,25 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable { return experimentalFeatures.contains(feature) } } + +extension SourceKitLSPOptions { + /// Options proxy to avoid public import of `SKLogging`. + /// + /// We can't conform `SourceKitLSPOptions` to `CustomLogStringConvertible` because that would require a public import + /// of `SKLogging`. Instead, define a package type that performs the logging of `SourceKitLSPOptions`. + package struct LoggingProxy: CustomLogStringConvertible { + let options: SourceKitLSPOptions + + package var description: String { + options.prettyPrintedJSON + } + + package var redactedDescription: String { + options.prettyPrintedRedactedJSON + } + } + + package var loggingProxy: LoggingProxy { + LoggingProxy(options: self) + } +} diff --git a/Sources/SourceKitLSP/SourceKitLSPServer.swift b/Sources/SourceKitLSP/SourceKitLSPServer.swift index 58b5eb835..ed1d0b2f0 100644 --- a/Sources/SourceKitLSP/SourceKitLSPServer.swift +++ b/Sources/SourceKitLSP/SourceKitLSPServer.swift @@ -917,7 +917,7 @@ extension SourceKitLSPServer { ) ) logger.log("Creating workspace at \(workspaceFolder.forLogging)") - logger.logFullObjectInMultipleLogMessages(header: "Options for workspace", options.loggingProxy) + logger.logFullObjectInMultipleLogMessages(header: "Workspace options", options.loggingProxy) let workspace = await Workspace( sourceKitLSPServer: self, @@ -1003,7 +1003,7 @@ extension SourceKitLSPServer { } logger.log("Initialized SourceKit-LSP") - logger.logFullObjectInMultipleLogMessages(header: "SourceKit-LSP Options", options.loggingProxy) + logger.logFullObjectInMultipleLogMessages(header: "Global options", options.loggingProxy) await workspaceQueue.async { [hooks] in if let workspaceFolders = req.workspaceFolders { @@ -2807,27 +2807,3 @@ fileprivate extension URL { return other.pathComponents[0..