diff --git a/src/Core/Loggers/QsharpLogger.cs b/src/Core/Loggers/QsharpLogger.cs index 9808080066..513585f6b2 100644 --- a/src/Core/Loggers/QsharpLogger.cs +++ b/src/Core/Loggers/QsharpLogger.cs @@ -32,22 +32,24 @@ public QSharpLogger(ILogger logger, int lineNrOffset = 0) : this.Logs = new List(); } - public static LogLevel MapLevel(LSP.DiagnosticSeverity original) - { - switch (original) + // NB: We define both a method which takes a + // Nullable and a plain DiagnosticSeverity + // value directly, as different versions of the LSP client API + // vary in their handling of nullablity of diagnostic severity. + // This allows IQ# to build with both different versions. + // At some point, the non-nullable overload should be removed. + public static LogLevel MapLevel(LSP.DiagnosticSeverity? original) => + original switch { - case LSP.DiagnosticSeverity.Error: - return LogLevel.Error; - case LSP.DiagnosticSeverity.Warning: - return LogLevel.Warning; - case LSP.DiagnosticSeverity.Information: - return LogLevel.Information; - case LSP.DiagnosticSeverity.Hint: - return LogLevel.Debug; - default: - return LogLevel.Trace; - } - } + LSP.DiagnosticSeverity.Error => LogLevel.Error, + LSP.DiagnosticSeverity.Warning => LogLevel.Warning, + LSP.DiagnosticSeverity.Information => LogLevel.Information, + LSP.DiagnosticSeverity.Hint => LogLevel.Debug, + _ => LogLevel.Trace + }; + + public static LogLevel MapLevel(LSP.DiagnosticSeverity original) => + MapLevel((LSP.DiagnosticSeverity?)original); public bool HasErrors => Logs