Skip to content

Fix/init capabilities #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Protocol/Models/BooleanOr.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
public struct BooleanOr<T>
public class BooleanOr<T>
{
private T _value;
private bool? _bool;
Expand Down Expand Up @@ -48,7 +48,7 @@ public object RawValue

public static implicit operator BooleanOr<T>(T value)
{
return new BooleanOr<T>(value);
return value != null ? new BooleanOr<T>(value) : null;
}

public static implicit operator BooleanOr<T>(bool value)
Expand Down
8 changes: 4 additions & 4 deletions src/Protocol/Serialization/Converters/BooleanOrConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -29,7 +29,7 @@ private static void WriteJsonGeneric<T>(JsonWriter writer, BooleanOr<T> value, J
return;
}

if (value.IsBool && value.Bool)
if (value.IsBool)
{
new JValue(value.Bool).WriteTo(writer);
return;
Expand Down Expand Up @@ -57,11 +57,11 @@ private static BooleanOr<T> ReadJsonGeneric<T>(JsonReader reader, object existin
return new BooleanOr<T>(JObject.Load(reader).ToObject<T>(serializer));
}

return new BooleanOr<T>();
return new BooleanOr<T>(default(T));
}

public override bool CanRead => true;

public override bool CanConvert(Type objectType) => objectType.GetTypeInfo().IsGenericType && objectType.GetTypeInfo().GetGenericTypeDefinition() == typeof(BooleanOr<>);
}
}
}
20 changes: 20 additions & 0 deletions test/Lsp.Tests/Capabilities/Server/ServerCapabilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
using OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities;
using Xunit;
Expand Down Expand Up @@ -59,6 +60,10 @@ public void SimpleTest(string expected)
WillSaveWaitUntil = true
}),
WorkspaceSymbolProvider = true,
ColorProvider = true,
FoldingRangeProvider = true,
ImplementationProvider = true,
TypeDefinitionProvider = true
};
var result = Fixture.SerializeObject(model);

Expand All @@ -67,5 +72,20 @@ public void SimpleTest(string expected)
var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<ServerCapabilities>(expected);
deresult.Should().BeEquivalentTo(model);
}

[Theory, JsonFixture]
public void Optional(string expected)
{
var model = new ServerCapabilities {
ColorProvider = (ColorOptions)null
};

var result = Fixture.SerializeObject(model);

result.Should().Be(expected);

var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<ServerCapabilities>(expected);
deresult.Should().BeEquivalentTo(model);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"hoverProvider": false,
"definitionProvider": false,
"referencesProvider": false,
"documentHighlightProvider": false,
"documentSymbolProvider": false,
"workspaceSymbolProvider": false,
"documentFormattingProvider": false,
"documentRangeFormattingProvider": false,
"experimental": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"experimental": {
"abc": "123"
},
"typeDefinitionProvider": null,
"implementationProvider": null,
"colorProvider": null,
"foldingRangeProvider": null
"typeDefinitionProvider": true,
"implementationProvider": true,
"colorProvider": true,
"foldingRangeProvider": true
}
6 changes: 1 addition & 5 deletions test/Lsp.Tests/Models/InitializeResultTests_$SimpleTest.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
},
"experimental": {
"abc": "123"
},
"typeDefinitionProvider": null,
"implementationProvider": null,
"colorProvider": null,
"foldingRangeProvider": null
}
}
}