Skip to content

Commit 91f7859

Browse files
Change TagSupport to use Supports<> helper class (#234)
* Change TagSupport to use Supports<> helper class This was done through the UI... there may be actual code breaks that I can get to. * Updated with unit tests
1 parent 954496d commit 91f7859

File tree

7 files changed

+79
-6
lines changed

7 files changed

+79
-6
lines changed

src/Protocol/Client/Capabilities/CompletionItemCapability.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class CompletionItemCapability
4343
[Optional]
4444
public bool PreselectSupport { get; set; }
4545

46-
4746
/// <summary>
4847
/// Client supports the tag property on a completion item. Clients supporting
4948
/// tags have to handle unknown tags gracefully. Clients especially need to
@@ -53,6 +52,6 @@ public class CompletionItemCapability
5352
/// @since 3.15.0
5453
/// </summary>
5554
[Optional]
56-
public CompletionItemTagSupportCapability TagSupport { get; set; }
55+
public Supports<CompletionItemTagSupportCapability> TagSupport { get; set; }
5756
}
5857
}

src/Protocol/Client/Capabilities/PublishDiagnosticsCapability.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public class PublishDiagnosticsCapability
2020
/// @since 3.15.0
2121
/// </summary>
2222
[Optional]
23-
public PublishDiagnosticsTagSupportCapability TagSupport { get; set; }
23+
public Supports<PublishDiagnosticsTagSupportCapability> TagSupport { get; set; }
2424
}
2525
}

src/Protocol/Models/CompletionItemTag.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33

44
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
55
{
6-
[JsonConverter(typeof(NumberEnumConverter))]
76
/// <summary>
87
/// Completion item tags are extra annotations that tweak the rendering of a completion
98
/// item.
109
///
1110
/// @since 3.15.0
1211
/// </summary>
12+
[JsonConverter(typeof(NumberEnumConverter))]
1313
public enum CompletionItemTag
1414
{
1515
/// <summary>
1616
/// Render a completion as obsolete, usually using a strike-out.
1717
/// </summary>
1818
Deprecated = 1
1919
}
20-
}
20+
}

src/Protocol/Serialization/ContractResolver.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
5858
property.NullValueHandling = NullValueHandling.Ignore;
5959
}
6060

61+
if (typeof(ISupports).IsAssignableFrom(property.PropertyType))
62+
{
63+
property.ValueProvider = new SupportsValueProvider(property.ValueProvider);
64+
}
65+
6166
if (property.DeclaringType == typeof(CompletionItem) && property.PropertyType == typeof(CompletionItemKind))
6267
{
6368
property.ValueProvider = new RangeValueProvider<CompletionItemKind>(property.ValueProvider, _completionItemKinds);
@@ -76,6 +81,27 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
7681
return property;
7782
}
7883

84+
class SupportsValueProvider : IValueProvider
85+
{
86+
private readonly IValueProvider _valueProvider;
87+
public SupportsValueProvider(IValueProvider valueProvider)
88+
{
89+
_valueProvider = valueProvider;
90+
}
91+
public void SetValue(object target, object value)
92+
{
93+
_valueProvider.SetValue(target, value);
94+
}
95+
96+
public object GetValue(object target)
97+
{
98+
return _valueProvider.GetValue(target) switch {
99+
ISupports supports when supports.IsSupported => supports,
100+
_ => null
101+
};
102+
}
103+
}
104+
79105
class RangeValueProvider<T> : IValueProvider
80106
where T : struct
81107
{

src/Protocol/Serialization/Converters/SupportsConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
3535
}
3636
else
3737
{
38-
serializer.Serialize(writer, null);
38+
writer.WriteNull();
3939
}
4040
}
4141

test/Lsp.Tests/Capabilities/Client/CompletionItemCapabilityTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
2+
using System.Linq;
23
using FluentAssertions;
34
using Newtonsoft.Json;
45
using OmniSharp.Extensions.LanguageServer.Protocol;
56
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
7+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
68
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
79
using Xunit;
810

@@ -24,5 +26,22 @@ public void SimpleTest(string expected)
2426
var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<CompletionItemCapability>(expected);
2527
deresult.Should().BeEquivalentTo(model);
2628
}
29+
30+
[Fact]
31+
public void TagSupportTrue()
32+
{
33+
var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<CompletionItemCapability>("{\"tagSupport\":true}");
34+
deresult.Should().BeEquivalentTo(new CompletionItemCapability() {
35+
TagSupport = new Supports<CompletionItemTagSupportCapability>(true)
36+
});
37+
}
38+
39+
[Fact]
40+
public void TagSupportObject()
41+
{
42+
var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<CompletionItemCapability>("{\"tagSupport\":{\"valueSet\": [1]}}");
43+
deresult.TagSupport.IsSupported.Should().Be(true);
44+
deresult.TagSupport.Value.ValueSet.Should().Contain(CompletionItemTag.Deprecated);
45+
}
2746
}
2847
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using FluentAssertions;
2+
using OmniSharp.Extensions.LanguageServer.Protocol;
3+
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
4+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
5+
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
6+
using Xunit;
7+
8+
namespace Lsp.Tests.Capabilities.Client
9+
{
10+
public class PublishDiagnosticsCapabilityTests
11+
{
12+
[Fact]
13+
public void TagSupportTrue()
14+
{
15+
var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<PublishDiagnosticsCapability>("{\"tagSupport\":true}");
16+
deresult.Should().BeEquivalentTo(new PublishDiagnosticsCapability() {
17+
TagSupport = new Supports<PublishDiagnosticsTagSupportCapability>(true)
18+
});
19+
}
20+
21+
[Fact]
22+
public void TagSupportObject()
23+
{
24+
var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<PublishDiagnosticsCapability>("{\"tagSupport\":{\"valueSet\": [2,1]}}");
25+
deresult.TagSupport.IsSupported.Should().Be(true);
26+
deresult.TagSupport.Value.ValueSet.Should().ContainInOrder(DiagnosticTag.Deprecated, DiagnosticTag.Unnecessary);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)