public override void LogDiagnostic(Diagnostic diagnostic) { _writer.WriteObjectStart(); // result _writer.Write("ruleId", diagnostic.Id); string ruleKey = _descriptors.Add(diagnostic.Descriptor); if (ruleKey != diagnostic.Id) { _writer.Write("ruleKey", ruleKey); } _writer.Write("level", GetLevel(diagnostic.Severity)); string message = diagnostic.GetMessage(_culture); if (!string.IsNullOrEmpty(message)) { _writer.Write("message", message); } if (diagnostic.IsSuppressed) { _writer.WriteArrayStart("suppressionStates"); _writer.Write("suppressedInSource"); _writer.WriteArrayEnd(); } WriteLocations(diagnostic.Location, diagnostic.AdditionalLocations); WriteProperties(diagnostic); _writer.WriteObjectEnd(); // result }
public override void LogDiagnostic(Diagnostic diagnostic) { _writer.WriteObjectStart(); // result _writer.Write("ruleId", diagnostic.Id); int ruleIndex = _descriptors.Add(diagnostic.Descriptor); _writer.Write("ruleIndex", ruleIndex); _writer.Write("level", GetLevel(diagnostic.Severity)); string?message = diagnostic.GetMessage(_culture); if (!RoslynString.IsNullOrEmpty(message)) { _writer.WriteObjectStart("message"); _writer.Write("text", message); _writer.WriteObjectEnd(); } if (diagnostic.IsSuppressed) { _writer.WriteArrayStart("suppressions"); _writer.WriteObjectStart(); // suppression _writer.Write("kind", "inSource"); _writer.WriteObjectEnd(); // suppression _writer.WriteArrayEnd(); } WriteLocations(diagnostic.Location, diagnostic.AdditionalLocations); WriteResultProperties(diagnostic); _writer.WriteObjectEnd(); // result }
internal void LogDiagnostic(Diagnostic diagnostic, CultureInfo culture) { _writer.WriteObjectStart(); // result _writer.Write("ruleId", diagnostic.Id); _writer.Write("kind", GetKind(diagnostic.Severity)); WriteLocations(diagnostic.Location, diagnostic.AdditionalLocations); string message = diagnostic.GetMessage(culture); if (string.IsNullOrEmpty(message)) { message = "<None>"; } string description = diagnostic.Descriptor.Description.ToString(culture); if (string.IsNullOrEmpty(description)) { _writer.Write("fullMessage", message); } else { _writer.Write("shortMessage", message); _writer.Write("fullMessage", description); } _writer.Write("isSuppressedInSource", diagnostic.IsSuppressed); WriteTags(diagnostic); WriteProperties(diagnostic, culture); _writer.WriteObjectEnd(); // result }
/// <summary> /// Formats the <see cref="Diagnostic"/> message using the optional <see cref="IFormatProvider"/>. /// </summary> /// <param name="diagnostic">The diagnostic.</param> /// <param name="formatter">The formatter; or null to use the default formatter.</param> /// <returns>The formatted message.</returns> public virtual string Format(Diagnostic diagnostic, IFormatProvider formatter = null) { if (diagnostic == null) { throw new ArgumentNullException(nameof(diagnostic)); } var culture = formatter as CultureInfo; switch (diagnostic.Location.Kind) { case LocationKind.SourceFile: case LocationKind.XmlFile: case LocationKind.ExternalFile: var span = diagnostic.Location.GetLineSpan(); var mappedSpan = diagnostic.Location.GetMappedLineSpan(); if (!span.IsValid || !mappedSpan.IsValid) { goto default; } string path, basePath; if (mappedSpan.HasMappedPath) { path = mappedSpan.Path; basePath = span.Path; } else { path = span.Path; basePath = null; } return(string.Format(formatter, "{0}{1}: {2}: {3}", FormatSourcePath(path, basePath, formatter), FormatSourceSpan(mappedSpan.Span, formatter), GetMessagePrefix(diagnostic, culture), diagnostic.GetMessage(culture))); default: return(string.Format(formatter, "{0}: {1}", GetMessagePrefix(diagnostic, culture), diagnostic.GetMessage(culture))); } }
public override string GetMessage(IFormatProvider?formatProvider = null) { // Diagnostic '{0}: {1}' was programmatically suppressed by a DiagnosticSuppressor with suppression ID '{2}' and justification '{3}' var localizableMessageFormat = s_suppressionDiagnosticDescriptor.MessageFormat.ToString(formatProvider); return(string.Format(formatProvider, localizableMessageFormat, _originalDiagnostic.Id, _originalDiagnostic.GetMessage(formatProvider), _suppressionId, _suppressionJustification.ToString(formatProvider))); }
/* Microsoft.CodeAnalysis.Diagnostic is coupled to the source tree and other CodeDOM objects * so need to use an adapter. */ public static BuildResult.Diagnostic From(Microsoft.CodeAnalysis.Diagnostic data) { return(new BuildResult.Diagnostic { IsWarningAsError = data.IsWarningAsError, Severity = data.Severity, Location_IsInSource = data.Location.IsInSource, Location_StartLinePosition_Line = data.Location.GetLineSpan().StartLinePosition.Line, Location_StartLinePosition_Character = data.Location.GetLineSpan().StartLinePosition.Character, Location_FilePath = data.Location.SourceTree.FilePath, Id = data.Id, Message = data.GetMessage() }); }
public static DiagnosticMessage ToDiagnosticMessage(this Diagnostic self, FrameworkName targetFramework) { var mappedLineSpan = self.Location.GetMappedLineSpan(); return(new DiagnosticMessage( self.GetMessage(), RoslynDiagnosticFormatter.Format(self, targetFramework), mappedLineSpan.Path, ConvertSeverity(self.Severity), mappedLineSpan.StartLinePosition.Line + 1, mappedLineSpan.StartLinePosition.Character + 1, mappedLineSpan.EndLinePosition.Line + 1, mappedLineSpan.EndLinePosition.Character + 1)); }
internal static void LogDiagnostic(Diagnostic diagnostic, CultureInfo culture, ErrorLogger errorLogger) { if (errorLogger != null) { #pragma warning disable RS0013 // We need to invoke Diagnostic.Descriptor here to log all the metadata properties of the diagnostic. var issue = new Issue(diagnostic.Id, diagnostic.GetMessage(culture), diagnostic.Descriptor.Description.ToString(culture), diagnostic.Descriptor.Title.ToString(culture), diagnostic.Category, diagnostic.Descriptor.HelpLinkUri, diagnostic.IsEnabledByDefault, diagnostic.IsSuppressed, diagnostic.DefaultSeverity, diagnostic.Severity, diagnostic.WarningLevel, diagnostic.Location, diagnostic.AdditionalLocations, diagnostic.CustomTags, diagnostic.Properties); #pragma warning restore RS0013 errorLogger.LogIssue(issue); } }
public override void LogDiagnostic(Diagnostic diagnostic, SuppressionInfo?suppressionInfo) { _writer.WriteObjectStart(); // result _writer.Write("ruleId", diagnostic.Id); int ruleIndex = _descriptors.Add(diagnostic.Descriptor); _writer.Write("ruleIndex", ruleIndex); _writer.Write("level", GetLevel(diagnostic.Severity)); string?message = diagnostic.GetMessage(_culture); if (!RoslynString.IsNullOrEmpty(message)) { _writer.WriteObjectStart("message"); _writer.Write("text", message); _writer.WriteObjectEnd(); } if (diagnostic.IsSuppressed) { _writer.WriteArrayStart("suppressions"); _writer.WriteObjectStart(); // suppression _writer.Write("kind", "inSource"); string?justification = suppressionInfo?.Attribute?.DecodeNamedArgument <string>( "Justification", SpecialType.System_String ); if (justification != null) { _writer.Write("justification", justification); } _writer.WriteObjectEnd(); // suppression _writer.WriteArrayEnd(); } WriteLocations(diagnostic.Location, diagnostic.AdditionalLocations); WriteResultProperties(diagnostic); _writer.WriteObjectEnd(); // result }
public static string Stringize(this Diagnostic e) { var retVal = string.Empty; if (e.Location.IsInSource) { retVal = e.Location.SourceSpan.ToString() + ": "; } else if (e.Location.IsInMetadata) { return("metadata: "); } else { return("no location: "); } retVal = e.Severity.ToString() + " " + e.Id + ": " + e.GetMessage(CultureInfo.CurrentCulture); return(retVal); }
public override string GetMessage(IFormatProvider?formatProvider = null) => _originalUnsuppressedDiagnostic.GetMessage(formatProvider);
public static string Inspect(this Diagnostic e) => e.Location.IsInSource ? $"{e.Severity} {e.Id}: {e.GetMessage(CultureInfo.CurrentCulture)}" : e.Location.IsInMetadata ? "metadata: " : "no location: ";
protected override void Populate(TextWriter trapFile) { trapFile.diagnostics(this, (int)diagnostic.Severity, diagnostic.Id, diagnostic.Descriptor.Title.ToString(), diagnostic.GetMessage(), Extraction.Entities.Location.Create(cx, diagnostic.Location)); }
public Diagnostic(Context cx, Microsoft.CodeAnalysis.Diagnostic diag) : base(cx) { cx.Emit(Tuples.diagnostics(this, (int)diag.Severity, diag.Id, diag.Descriptor.Title.ToString(), diag.GetMessage(), Extraction.Entities.Location.Create(cx, diag.Location))); }