-
Notifications
You must be signed in to change notification settings - Fork 0
/
Error.cs
66 lines (62 loc) · 2.2 KB
/
Error.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Microsoft.CodeAnalysis;
namespace Soothsharp.Translation
{
/// <summary>
/// Represents a squiggly-type error that occured as a result of translation or verification.
/// It is not necessarily an error, it might just as well be a warning.
/// </summary>
public class Error
{
/// <summary>
/// Information about this kind of error.
/// </summary>
public SoothsharpDiagnostic Diagnostic;
/// <summary>
/// Arguments to be passed to the <see cref="SoothsharpDiagnostic"/> message.
/// </summary>
public object[] DiagnosticArguments;
/// <summary>
/// The syntax node with which this error is associated, or null if there is no such node.
/// </summary>
public SyntaxNode Node;
/// <summary>
/// Gets the 1-indexed column of the associated syntax node, or else 0.
/// </summary>
private int CsharpColumn
{
get
{
if (this.Node == null) return 0;
return this.Node.GetLocation().GetLineSpan().StartLinePosition.Character + 1;
}
}
/// <summary>
/// Gets the 1-indexed line of the associated syntax node, or else 0.
/// </summary>
public int CsharpLine
{
get
{
if (this.Node == null) return 0;
return this.Node.GetLocation().GetLineSpan().StartLinePosition.Line + 1;
}
}
public Error(SoothsharpDiagnostic diagnostic, SyntaxNode node, params object[] diagnosticArguments)
{
this.Diagnostic = diagnostic;
this.DiagnosticArguments = diagnosticArguments;
this.Node = node;
}
/// <summary>
/// This ToString() method is used when printing the error to the commandline console.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return this.CsharpLine + ":" +
this.CsharpColumn + " " +
this.Diagnostic.ErrorCode + ": " +
string.Format(this.Diagnostic.Caption, this.DiagnosticArguments);
}
}
}