87 lines
3.3 KiB
C#
87 lines
3.3 KiB
C#
using System;
|
|
using Microsoft.CodeAnalysis.Text;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp;
|
|
|
|
internal sealed class CommandLineDiagnosticFormatter : CSharpDiagnosticFormatter
|
|
{
|
|
private readonly string _baseDirectory;
|
|
|
|
private readonly Lazy<string> _lazyNormalizedBaseDirectory;
|
|
|
|
private readonly bool _displayFullPaths;
|
|
|
|
private readonly bool _displayEndLocations;
|
|
|
|
internal CommandLineDiagnosticFormatter(string baseDirectory, bool displayFullPaths, bool displayEndLocations)
|
|
{
|
|
_baseDirectory = baseDirectory;
|
|
_displayFullPaths = displayFullPaths;
|
|
_displayEndLocations = displayEndLocations;
|
|
_lazyNormalizedBaseDirectory = new Lazy<string>(() => FileUtilities.TryNormalizeAbsolutePath(baseDirectory));
|
|
}
|
|
|
|
internal override string FormatSourceSpan(LinePositionSpan span, IFormatProvider formatter)
|
|
{
|
|
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
|
|
LinePosition val;
|
|
if (_displayEndLocations)
|
|
{
|
|
object[] array = new object[4];
|
|
val = ((LinePositionSpan)(ref span)).Start;
|
|
array[0] = ((LinePosition)(ref val)).Line + 1;
|
|
val = ((LinePositionSpan)(ref span)).Start;
|
|
array[1] = ((LinePosition)(ref val)).Character + 1;
|
|
val = ((LinePositionSpan)(ref span)).End;
|
|
array[2] = ((LinePosition)(ref val)).Line + 1;
|
|
val = ((LinePositionSpan)(ref span)).End;
|
|
array[3] = ((LinePosition)(ref val)).Character + 1;
|
|
return string.Format(formatter, "({0},{1},{2},{3})", array);
|
|
}
|
|
val = ((LinePositionSpan)(ref span)).Start;
|
|
object arg = ((LinePosition)(ref val)).Line + 1;
|
|
val = ((LinePositionSpan)(ref span)).Start;
|
|
return string.Format(formatter, "({0},{1})", arg, ((LinePosition)(ref val)).Character + 1);
|
|
}
|
|
|
|
internal override string FormatSourcePath(string path, string basePath, IFormatProvider formatter)
|
|
{
|
|
string text = FileUtilities.NormalizeRelativePath(path, basePath, _baseDirectory);
|
|
if (text == null)
|
|
{
|
|
return path;
|
|
}
|
|
if (!_displayFullPaths)
|
|
{
|
|
return RelativizeNormalizedPath(text);
|
|
}
|
|
return text;
|
|
}
|
|
|
|
internal string RelativizeNormalizedPath(string normalizedPath)
|
|
{
|
|
string value = _lazyNormalizedBaseDirectory.Value;
|
|
if (value == null)
|
|
{
|
|
return normalizedPath;
|
|
}
|
|
if (PathUtilities.IsSameDirectoryOrChildOf(PathUtilities.GetDirectoryName(normalizedPath), value))
|
|
{
|
|
return normalizedPath.Substring(PathUtilities.IsDirectorySeparator(StringExtensions.Last(value)) ? value.Length : (value.Length + 1));
|
|
}
|
|
return normalizedPath;
|
|
}
|
|
}
|