Skip to content

Commit 1ad4da1

Browse files
More serialization changes to bring the serializer everywhere. Started work on fixing tests
1 parent 8cf6021 commit 1ad4da1

File tree

129 files changed

+650
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+650
-371
lines changed

src/Client/Protocol/LspConnection.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using OmniSharp.Extensions.LanguageServer.Client.Handlers;
1515
using OmniSharp.Extensions.LanguageServer.Client.Logging;
1616
using OmniSharp.Extensions.LanguageServer.Protocol;
17+
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1718
using JsonRpcMessages = OmniSharp.Extensions.JsonRpc.Server.Messages;
1819

1920
namespace OmniSharp.Extensions.LanguageServer.Client.Protocol
@@ -124,6 +125,8 @@ public sealed class LspConnection
124125
/// </summary>
125126
Task _dispatchLoop;
126127

128+
private JsonSerializerSettings _jsonSerializerSettings;
129+
127130
/// <summary>
128131
/// Create a new <see cref="LspConnection"/>.
129132
/// </summary>
@@ -156,6 +159,8 @@ public LspConnection(ILoggerFactory loggerFactory, Stream input, Stream output)
156159
Log = loggerFactory.CreateLogger<LspConnection>();
157160
_input = input;
158161
_output = output;
162+
// What does client version do? Do we have to negotaite this?
163+
_jsonSerializerSettings = Serializer.CreateSerializerSettings(ClientVersion.Lsp3);
159164
}
160165

161166
/// <summary>
@@ -654,7 +659,7 @@ async Task SendMessage<TMessage>(TMessage message)
654659
if (message == null)
655660
throw new ArgumentNullException(nameof(message));
656661

657-
string payload = JsonConvert.SerializeObject(message);
662+
string payload = JsonConvert.SerializeObject(message, _jsonSerializerSettings);
658663
byte[] payloadBuffer = PayloadEncoding.GetBytes(payload);
659664

660665
byte[] headerBuffer = HeaderEncoding.GetBytes(
@@ -754,7 +759,7 @@ async Task<ServerMessage> ReceiveMessage()
754759
Log.LogDebug("Received entire payload ({ReceivedByteCount} bytes).", received);
755760

756761
string responseBody = PayloadEncoding.GetString(requestBuffer);
757-
ServerMessage message = JsonConvert.DeserializeObject<ServerMessage>(responseBody);
762+
ServerMessage message = JsonConvert.DeserializeObject<ServerMessage>(responseBody, _jsonSerializerSettings);
758763

759764
Log.LogDebug("Read response body {ResponseBody}.", responseBody);
760765

src/JsonRpc/Client/Notification.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace OmniSharp.Extensions.JsonRpc.Client
55
{
6+
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
67
public class Notification
78
{
89
public string ProtocolVersion { get; } = "2.0";

src/JsonRpc/Client/Request.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
22
using Newtonsoft.Json.Serialization;
33

44
namespace OmniSharp.Extensions.JsonRpc.Client
55
{
6+
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
67
public class Request
78
{
89
public object Id { get; set; }

src/JsonRpc/Client/Response.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace OmniSharp.Extensions.JsonRpc.Client
55
{
6+
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
67
public class Response
78
{
89
public Response(object id)

src/JsonRpc/InputHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class InputHandler : IInputHandler
2626
private Thread _inputThread;
2727
private readonly IRequestRouter _requestRouter;
2828
private readonly IResponseRouter _responseRouter;
29+
private readonly JsonSerializerSettings _jsonSerializerSettings;
2930
private readonly ILogger<InputHandler> _logger;
3031
private readonly IScheduler _scheduler;
3132

@@ -36,7 +37,8 @@ public InputHandler(
3637
IRequestProcessIdentifier requestProcessIdentifier,
3738
IRequestRouter requestRouter,
3839
IResponseRouter responseRouter,
39-
ILoggerFactory loggerFactory
40+
ILoggerFactory loggerFactory,
41+
JsonSerializerSettings jsonSerializerSettings
4042
)
4143
{
4244
if (!input.CanRead) throw new ArgumentException($"must provide a readable stream for {nameof(input)}", nameof(input));
@@ -46,6 +48,7 @@ ILoggerFactory loggerFactory
4648
_requestProcessIdentifier = requestProcessIdentifier;
4749
_requestRouter = requestRouter;
4850
_responseRouter = responseRouter;
51+
_jsonSerializerSettings = jsonSerializerSettings;
4952
_logger = loggerFactory.CreateLogger<InputHandler>();
5053
_scheduler = new ProcessScheduler(loggerFactory);
5154
_inputThread = new Thread(ProcessInputStream) { IsBackground = true, Name = "ProcessInputStream" };
@@ -155,7 +158,7 @@ private void HandleRequest(string request)
155158
}
156159
else if (response is ServerError serverError)
157160
{
158-
tcs.SetException(new Exception(JsonConvert.SerializeObject(serverError.Error)));
161+
tcs.SetException(new Exception(JsonConvert.SerializeObject(serverError.Error, _jsonSerializerSettings)));
159162
}
160163
}
161164

src/JsonRpc/OutputHandler.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.IO;
44
using System.Text;
@@ -10,14 +10,16 @@ namespace OmniSharp.Extensions.JsonRpc
1010
public class OutputHandler : IOutputHandler
1111
{
1212
private readonly Stream _output;
13+
private readonly JsonSerializerSettings _jsonSerializerSettings;
1314
private readonly Thread _thread;
1415
private readonly BlockingCollection<object> _queue;
1516
private readonly CancellationTokenSource _cancel;
1617

17-
public OutputHandler(Stream output)
18+
public OutputHandler(Stream output, JsonSerializerSettings jsonSerializerSettings)
1819
{
1920
if (!output.CanWrite) throw new ArgumentException($"must provide a writable stream for {nameof(output)}", nameof(output));
2021
_output = output;
22+
_jsonSerializerSettings = jsonSerializerSettings;
2123
_queue = new BlockingCollection<object>();
2224
_cancel = new CancellationTokenSource();
2325
_thread = new Thread(ProcessOutputQueue) { IsBackground = true, Name = "ProcessOutputQueue" };
@@ -42,7 +44,7 @@ private void ProcessOutputQueue()
4244
{
4345
if (_queue.TryTake(out var value, Timeout.Infinite, token))
4446
{
45-
var content = JsonConvert.SerializeObject(value);
47+
var content = JsonConvert.SerializeObject(value, _jsonSerializerSettings);
4648
var contentBytes = System.Text.Encoding.UTF8.GetBytes(content);
4749

4850
// TODO: Is this lsp specific??

src/Protocol/Client/Capabilities/CompletionCapability.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public class CompletionCapability : DynamicCapability, ConnectedCapability<IComp
1414
/// The client supports to send additional context information for a `textDocument/completion` request.
1515
/// </summary>
1616
[Optional]
17-
public bool? ContextSupport { get; set; }
17+
public bool ContextSupport { get; set; }
1818
}
1919
}

src/Protocol/Client/Capabilities/CompletionItemCapability.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public class CompletionItemCapability
1515
/// that is typing in one will update others too.
1616
/// </summary>
1717
[Optional]
18-
public bool? SnippetSupport { get; set; }
18+
public bool SnippetSupport { get; set; }
1919

2020
/// <summary>
2121
/// Client supports commit characters on a completion item.
2222
/// </summary>
2323
[Optional]
24-
public bool? CommitCharactersSupport { get; set; }
24+
public bool CommitCharactersSupport { get; set; }
2525

2626
/// <summary>
2727
/// Client supports the follow content formats for the documentation

src/Protocol/Client/Capabilities/DynamicCapability.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
22
using Newtonsoft.Json.Serialization;
33

44
namespace OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities
@@ -9,6 +9,6 @@ public class DynamicCapability
99
/// Whether completion supports dynamic registration.
1010
/// </summary>
1111
[Optional]
12-
public bool? DynamicRegistration { get; set; }
12+
public bool DynamicRegistration { get; set; }
1313
}
1414
}

src/Protocol/Client/Capabilities/SynchronizationCapability.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ public class SynchronizationCapability : DynamicCapability, ConnectedCapability<
99
/// The client supports sending will save notifications.
1010
/// </summary>
1111
[Optional]
12-
public bool? WillSave { get; set; }
12+
public bool WillSave { get; set; }
1313

1414
/// <summary>
1515
/// The client supports sending a will save request and
1616
/// waits for a response providing text edits which will
1717
/// be applied to the document before it is saved.
1818
/// </summary>
1919
[Optional]
20-
public bool? WillSaveWaitUntil { get; set; }
20+
public bool WillSaveWaitUntil { get; set; }
2121

2222
/// <summary>
2323
/// The client supports did save notifications.
2424
/// </summary>
2525
[Optional]
26-
public bool? DidSave { get; set; }
26+
public bool DidSave { get; set; }
2727
}
2828
}

0 commit comments

Comments
 (0)