Skip to content

Commit d67b8ec

Browse files
drsorandavid-driscoll
authored andcommitted
Changes for #175 to return a Location object for diagnostic related information (#176)
* return a Location object instead of a string for the location of a diagnostic related information * add test for related information with diagnostics
1 parent 22ebd1f commit d67b8ec

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

src/Protocol/Models/DiagnosticRelatedInformation.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class DiagnosticRelatedInformation
1010
/// <summary>
1111
/// The location of this related diagnostic information.
1212
/// </summary>
13-
public string Location { get; set; }
13+
public Location Location { get; set; }
1414

1515
/// <summary>
1616
/// The message of this related diagnostic information.

test/Lsp.Tests/Models/DiagnosticTests.cs

+35
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,41 @@ public void SimpleTest(string expected)
2929
deresult.Should().BeEquivalentTo(model);
3030
}
3131

32+
[Theory, JsonFixture]
33+
public void RelatedInformationTest(string expected)
34+
{
35+
var model = new Diagnostic() {
36+
Code = new DiagnosticCode("abcd"),
37+
Message = "message",
38+
Range = new Range(new Position(1, 1), new Position(2, 2)),
39+
Severity = DiagnosticSeverity.Error,
40+
Source = "csharp",
41+
RelatedInformation = new Container<DiagnosticRelatedInformation>(
42+
new DiagnosticRelatedInformation {
43+
Location = new Location {
44+
Uri = new Uri("file:///abc/def.cs"),
45+
Range = new Range(new Position(1, 2), new Position(3, 4))
46+
},
47+
Message = "related message 1"
48+
},
49+
new DiagnosticRelatedInformation {
50+
Location = new Location {
51+
Uri = new Uri("file:///def/ghi.cs"),
52+
Range = new Range(new Position(5, 6), new Position(7, 8))
53+
},
54+
Message = "related message 2"
55+
}
56+
)
57+
};
58+
59+
var result = Fixture.SerializeObject(model);
60+
61+
result.Should().Be(expected);
62+
63+
var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<Diagnostic>(expected);
64+
deresult.Should().BeEquivalentTo(model);
65+
}
66+
3267
[Theory, JsonFixture]
3368
public void OptionalTest(string expected)
3469
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"range": {
3+
"start": {
4+
"line": 1,
5+
"character": 1
6+
},
7+
"end": {
8+
"line": 2,
9+
"character": 2
10+
}
11+
},
12+
"severity": 1,
13+
"code": "abcd",
14+
"source": "csharp",
15+
"message": "message",
16+
"relatedInformation": [
17+
{
18+
"location": {
19+
"uri": "file:///abc/def.cs",
20+
"range": {
21+
"start": {
22+
"line": 1,
23+
"character": 2
24+
},
25+
"end": {
26+
"line": 3,
27+
"character": 4
28+
}
29+
}
30+
},
31+
"message": "related message 1"
32+
},
33+
{
34+
"location": {
35+
"uri": "file:///def/ghi.cs",
36+
"range": {
37+
"start": {
38+
"line": 5,
39+
"character": 6
40+
},
41+
"end": {
42+
"line": 7,
43+
"character": 8
44+
}
45+
}
46+
},
47+
"message": "related message 2"
48+
}
49+
]
50+
}

0 commit comments

Comments
 (0)