Skip to content

Commit 5ee50d8

Browse files
authored
Simplify DiagnosticConverter (#292)
Only a few fields on Diagnostic are its own, and the rest can be delegated to the existing DiagnosticDescriptor renderer. This both simplifies the implementation, and makes Diagnostic's own output have clearer separation between own and "inherited" information.
1 parent 1cfd06a commit 5ee50d8

14 files changed

+134
-96
lines changed

readme.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,23 @@ An info file containing all metadata about the current state. eg any Diagnostics
162162
{
163163
Diagnostics: [
164164
{
165-
Id: theId,
166-
Title: the title,
167-
Severity: Info,
168-
WarningLevel: 1,
169165
Location: dir\theFile.cs: (1,2)-(3,4),
170-
MessageFormat: the message from {0},
171166
Message: the message from hello world generator,
172-
Category: the category
167+
Severity: Info,
168+
WarningLevel: 1,
169+
Descriptor: {
170+
Id: theId,
171+
Title: the title,
172+
MessageFormat: the message from {0},
173+
Category: the category,
174+
DefaultSeverity: Info,
175+
IsEnabledByDefault: true
176+
}
173177
}
174178
]
175179
}
176180
```
177-
<sup><a href='/src/Tests/SampleTest.Driver.verified.txt#L1-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-SampleTest.Driver.verified.txt' title='Start of snippet'>anchor</a></sup>
181+
<sup><a href='/src/Tests/SampleTest.Driver.verified.txt#L1-L18' title='Snippet source file'>snippet source</a> | <a href='#snippet-SampleTest.Driver.verified.txt' title='Start of snippet'>anchor</a></sup>
178182
<!-- endSnippet -->
179183

180184

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
Diagnostics: [
33
{
4-
Id: theId,
5-
Title: the title,
6-
Severity: Info,
7-
WarningLevel: 1,
84
Location: dir\theFile.cs: (1,2)-(3,4),
9-
MessageFormat: the message from {0},
105
Message: the message from hello world generator,
11-
Category: the category
6+
Severity: Info,
7+
WarningLevel: 1,
8+
Descriptor: {
9+
Id: theId,
10+
Title: the title,
11+
MessageFormat: the message from {0},
12+
Category: the category,
13+
DefaultSeverity: Info,
14+
IsEnabledByDefault: true
15+
}
1216
}
1317
]
1418
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
Diagnostics: [
33
{
4-
Id: theId,
5-
Title: the title,
6-
Severity: Info,
7-
WarningLevel: 1,
84
Location: dir\theFile.cs: (1,2)-(3,4),
9-
MessageFormat: the message from {0},
105
Message: the message from hello world generator,
11-
Category: the category
6+
Severity: Info,
7+
WarningLevel: 1,
8+
Descriptor: {
9+
Id: theId,
10+
Title: the title,
11+
MessageFormat: the message from {0},
12+
Category: the category,
13+
DefaultSeverity: Info,
14+
IsEnabledByDefault: true
15+
}
1216
}
1317
]
1418
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
Diagnostics: [
33
{
4-
Id: theId,
5-
Title: the title,
6-
Severity: Info,
7-
WarningLevel: 1,
84
Location: dir\theFile.cs: (1,2)-(3,4),
9-
MessageFormat: the message from {0},
105
Message: the message from hello world generator,
11-
Category: the category
6+
Severity: Info,
7+
WarningLevel: 1,
8+
Descriptor: {
9+
Id: theId,
10+
Title: the title,
11+
MessageFormat: the message from {0},
12+
Category: the category,
13+
DefaultSeverity: Info,
14+
IsEnabledByDefault: true
15+
}
1216
}
1317
]
1418
}

src/Tests/SampleTest.RunResult.verified.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ public static class HelloWorld
2727
],
2828
Diagnostics: [
2929
{
30-
Id: theId,
31-
Title: the title,
32-
Severity: Info,
33-
WarningLevel: 1,
3430
Location: dir\theFile.cs: (1,2)-(3,4),
35-
MessageFormat: the message from {0},
3631
Message: the message from hello world generator,
37-
Category: the category
32+
Severity: Info,
33+
WarningLevel: 1,
34+
Descriptor: {
35+
Id: theId,
36+
Title: the title,
37+
MessageFormat: the message from {0},
38+
Category: the category,
39+
DefaultSeverity: Info,
40+
IsEnabledByDefault: true
41+
}
3842
}
3943
]
4044
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
Diagnostics: [
33
{
4-
Id: theId,
5-
Title: the title,
6-
Severity: Info,
7-
WarningLevel: 1,
84
Location: dir\theFile.cs: (1,2)-(3,4),
9-
MessageFormat: the message from {0},
105
Message: the message from hello world generator,
11-
Category: the category
6+
Severity: Info,
7+
WarningLevel: 1,
8+
Descriptor: {
9+
Id: theId,
10+
Title: the title,
11+
MessageFormat: the message from {0},
12+
Category: the category,
13+
DefaultSeverity: Info,
14+
IsEnabledByDefault: true
15+
}
1216
}
1317
]
1418
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
Diagnostics: [
33
{
4-
Id: theId,
5-
Title: the title,
6-
Severity: Info,
7-
WarningLevel: 1,
84
Location: dir\theFile.vb: (1,2)-(3,4),
9-
MessageFormat: the message from {0},
105
Message: the message from hello world generator,
11-
Category: the category
6+
Severity: Info,
7+
WarningLevel: 1,
8+
Descriptor: {
9+
Id: theId,
10+
Title: the title,
11+
MessageFormat: the message from {0},
12+
Category: the category,
13+
DefaultSeverity: Info,
14+
IsEnabledByDefault: true
15+
}
1216
}
1317
]
1418
}
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
Diagnostics: [
33
{
4-
Id: theId,
5-
Title: the title,
4+
Message: the message from hello world generator,
65
Severity: Info,
76
WarningLevel: 1,
8-
MessageFormat: the message from {0},
9-
Message: the message from hello world generator,
10-
Category: the category
7+
Descriptor: {
8+
Id: theId,
9+
Title: the title,
10+
MessageFormat: the message from {0},
11+
Category: the category,
12+
DefaultSeverity: Info,
13+
IsEnabledByDefault: true
14+
}
1115
}
1216
]
1317
}

src/Tests/SampleVbTest.RunResult.verified.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ End Module
2424
],
2525
Diagnostics: [
2626
{
27-
Id: theId,
28-
Title: the title,
29-
Severity: Info,
30-
WarningLevel: 1,
3127
Location: dir\theFile.vb: (1,2)-(3,4),
32-
MessageFormat: the message from {0},
3328
Message: the message from hello world generator,
34-
Category: the category
29+
Severity: Info,
30+
WarningLevel: 1,
31+
Descriptor: {
32+
Id: theId,
33+
Title: the title,
34+
MessageFormat: the message from {0},
35+
Category: the category,
36+
DefaultSeverity: Info,
37+
IsEnabledByDefault: true
38+
}
3539
}
3640
]
3741
}

src/Tests/SampleVbTest.RunResultWithoutLocation.verified.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ End Module
2424
],
2525
Diagnostics: [
2626
{
27-
Id: theId,
28-
Title: the title,
27+
Message: the message from hello world generator,
2928
Severity: Info,
3029
WarningLevel: 1,
31-
MessageFormat: the message from {0},
32-
Message: the message from hello world generator,
33-
Category: the category
30+
Descriptor: {
31+
Id: theId,
32+
Title: the title,
33+
MessageFormat: the message from {0},
34+
Category: the category,
35+
DefaultSeverity: Info,
36+
IsEnabledByDefault: true
37+
}
3438
}
3539
]
3640
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
Diagnostics: [
33
{
4-
Id: theId,
5-
Title: the title,
6-
Severity: Info,
7-
WarningLevel: 1,
84
Location: dir\theFile.vb: (1,2)-(3,4),
9-
MessageFormat: the message from {0},
105
Message: the message from hello world generator,
11-
Category: the category
6+
Severity: Info,
7+
WarningLevel: 1,
8+
Descriptor: {
9+
Id: theId,
10+
Title: the title,
11+
MessageFormat: the message from {0},
12+
Category: the category,
13+
DefaultSeverity: Info,
14+
IsEnabledByDefault: true
15+
}
1216
}
1317
]
1418
}
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
Diagnostics: [
33
{
4-
Id: theId,
5-
Title: the title,
4+
Message: the message from hello world generator,
65
Severity: Info,
76
WarningLevel: 1,
8-
MessageFormat: the message from {0},
9-
Message: the message from hello world generator,
10-
Category: the category
7+
Descriptor: {
8+
Id: theId,
9+
Title: the title,
10+
MessageFormat: the message from {0},
11+
Category: the category,
12+
DefaultSeverity: Info,
13+
IsEnabledByDefault: true
14+
}
1115
}
1216
]
1317
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
Diagnostics: [
33
{
4-
Id: theId,
5-
Title: the title,
6-
Severity: Info,
7-
WarningLevel: 1,
84
Location: dir\theFile.cs: (1,2)-(3,4),
9-
MessageFormat: the message from {0},
105
Message: the message from hello world generator,
11-
Category: the category
6+
Severity: Info,
7+
WarningLevel: 1,
8+
Descriptor: {
9+
Id: theId,
10+
Title: the title,
11+
MessageFormat: the message from {0},
12+
Category: the category,
13+
DefaultSeverity: Info,
14+
IsEnabledByDefault: true
15+
}
1216
}
1317
]
1418
}

src/Verify.SourceGenerators/Converters/DiagnosticConverter.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,17 @@
44
public override void Write(VerifyJsonWriter writer, Diagnostic value)
55
{
66
writer.WriteStartObject();
7-
writer.WriteMember(value, value.Id, "Id");
8-
var descriptor = value.Descriptor;
9-
writer.WriteMember(value, descriptor.Title, "Title");
10-
writer.WriteMember(value, value.Severity, "Severity");
11-
writer.WriteMember(value, value.WarningLevel, "WarningLevel");
127
if (value.Location != Location.None)
138
{
149
writer.WriteMember(value, value.Location, "Location");
1510
}
16-
var description = descriptor.Description.ToString(CultureInfo.InvariantCulture);
17-
if (!string.IsNullOrWhiteSpace(description))
18-
{
19-
writer.WriteMember(value, description, "Description");
20-
}
21-
22-
var help = descriptor.HelpLinkUri;
23-
if (!string.IsNullOrWhiteSpace(help))
11+
writer.WriteMember(value, value.GetMessage(CultureInfo.InvariantCulture), "Message");
12+
writer.WriteMember(value, value.Severity, "Severity");
13+
if (value.WarningLevel != 0)
2414
{
25-
writer.WriteMember(value, help, "HelpLink");
15+
writer.WriteMember(value, value.WarningLevel, "WarningLevel");
2616
}
27-
28-
writer.WriteMember(value, descriptor.MessageFormat, "MessageFormat");
29-
writer.WriteMember(value, value.GetMessage(CultureInfo.InvariantCulture), "Message");
30-
writer.WriteMember(value, descriptor.Category, "Category");
31-
writer.WriteMember(value, descriptor.CustomTags, "CustomTags");
17+
writer.WriteMember(value, value.Descriptor, "Descriptor");
3218
writer.WriteEndObject();
3319
}
34-
}
20+
}

0 commit comments

Comments
 (0)