Skip to content

Commit 2023c05

Browse files
committed
Reduce the number of log messages to log the translation for token types and token modifiers from clangd to SourceKit-LSP
This used to produce ~40 log entries, which was pretty spammy. Compact them into 1
1 parent a22bf90 commit 2023c05

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

Sources/SourceKitLSP/Clang/SemanticTokenTranslator.swift

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ struct SemanticTokensLegendTranslator {
5353
logger.error("Token type '\(tokenType, privacy: .public)' from clangd does not exist in SourceKit-LSP's legend")
5454
tokenTypeTranslations[UInt32(index)] = .doesNotExistInSourceKitLSP
5555
case let sourceKitLSPIndex?:
56-
logger.info(
57-
"Token type '\(tokenType, privacy: .public)' from clangd at index \(index) translated to \(sourceKitLSPIndex)"
58-
)
5956
tokenTypeTranslations[UInt32(index)] = .translation(UInt32(sourceKitLSPIndex))
6057
}
6158
}
@@ -72,12 +69,35 @@ struct SemanticTokensLegendTranslator {
7269
)
7370
tokenModifierTranslations[UInt32(index)] = .doesNotExistInSourceKitLSP
7471
case let sourceKitLSPIndex?:
75-
logger.error(
76-
"Token modifier '\(tokenModifier, privacy: .public)' from clangd at index \(index) translated to \(sourceKitLSPIndex)"
77-
)
7872
tokenModifierTranslations[UInt32(index)] = .translation(UInt32(sourceKitLSPIndex))
7973
}
8074
}
75+
struct TranslationsLogObject: CustomLogStringConvertible {
76+
let translations: [UInt32: Translation]
77+
78+
var description: String { redactedDescription }
79+
80+
var redactedDescription: String {
81+
translations.sorted { $0.key < $1.key }.map { entry in
82+
switch entry.value {
83+
case .translation(let translation):
84+
return "\(entry.key): \(translation)"
85+
case .doesNotExistInSourceKitLSP:
86+
return "\(entry.key): does not exist"
87+
}
88+
}.joined(separator: "\n")
89+
}
90+
}
91+
logger.logFullObjectInMultipleLogMessages(
92+
level: .info,
93+
header: "clangd token type translations",
94+
TranslationsLogObject(translations: tokenTypeTranslations)
95+
)
96+
logger.logFullObjectInMultipleLogMessages(
97+
level: .info,
98+
header: "clangd token modifier translations",
99+
TranslationsLogObject(translations: tokenModifierTranslations)
100+
)
81101
self.tokenModifierTranslations = tokenModifierTranslations
82102

83103
var tokenModifierTranslationBitmask: UInt32 = 0

0 commit comments

Comments
 (0)