-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from OmniSharp/fix/error
Breaking: Error object was misshaped, textdocumentsync double registered.
- Loading branch information
Showing
46 changed files
with
422 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
using OmniSharp.Extensions.JsonRpc.Server.Messages; | ||
|
||
namespace OmniSharp.Extensions.JsonRpc | ||
{ | ||
|
||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy)), JsonConverter(typeof(RpcErrorConverter))] | ||
public class RpcError<T> | ||
{ | ||
public RpcError(object id, ErrorMessage<T> message) : this(id, message, "2.0") | ||
{ | ||
} | ||
|
||
[JsonConstructor] | ||
public RpcError(object id, ErrorMessage<T> message, string protocolVersion) | ||
{ | ||
Id = id; | ||
Error = message; | ||
ProtocolVersion = protocolVersion; | ||
} | ||
|
||
public string ProtocolVersion { get; set; } | ||
|
||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)] | ||
public object Id { get; } | ||
|
||
public ErrorMessage<T> Error { get; } | ||
} | ||
|
||
public class RpcError : RpcError<object> | ||
{ | ||
public RpcError(object id, ErrorMessage<object> message) : this(id, message, "2.0") | ||
{ | ||
} | ||
|
||
[JsonConstructor] | ||
public RpcError(object id, ErrorMessage<object> message, string protocolVersion) : base(id, message, protocolVersion) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Reflection; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using OmniSharp.Extensions.JsonRpc.Server.Messages; | ||
|
||
namespace OmniSharp.Extensions.JsonRpc | ||
{ | ||
public class RpcErrorConverter : JsonConverter | ||
{ | ||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
var obj = JObject.Load(reader); | ||
|
||
var messageDataType = objectType == typeof(RpcError) | ||
? typeof(object) | ||
: objectType.GetTypeInfo().GetGenericArguments()[0]; | ||
|
||
object requestId = null; | ||
if (obj.TryGetValue("id", out var id)) | ||
{ | ||
var idString = id.Type == JTokenType.String ? (string)id : null; | ||
var idLong = id.Type == JTokenType.Integer ? (long?)id : null; | ||
requestId = idString ?? (idLong.HasValue ? (object)idLong.Value : null); | ||
} | ||
|
||
object data = null; | ||
if (obj.TryGetValue("error", out var dataToken)) | ||
{ | ||
var errorMessageType = typeof(ErrorMessage<>).MakeGenericType(messageDataType); | ||
data = dataToken.ToObject(errorMessageType); | ||
} | ||
|
||
return Activator.CreateInstance(objectType, requestId, data, obj["protocolVersion"].ToString()); | ||
} | ||
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
return objectType == typeof(RpcError) || | ||
(objectType.GetTypeInfo().IsGenericType && objectType.GetTypeInfo().GetGenericTypeDefinition() == typeof(RpcError<>)); | ||
} | ||
|
||
public override bool CanWrite { get; } = false; | ||
public override bool CanRead { get; } = true; | ||
} | ||
} |
Oops, something went wrong.