Skip to content

Commit cde3283

Browse files
Merge pull request #51 from OmniSharp/refactor/protocol
[WIP] bring up to date with latest spec
2 parents cf54ed6 + 69f9d6b commit cde3283

File tree

338 files changed

+2932
-1308
lines changed

Some content is hidden

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

338 files changed

+2932
-1308
lines changed

language-server-protocol.sha.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- This is the last commit we caught up with https://github.com/Microsoft/language-server-protocol
2+
05e3af34464671a788679080f06558db52d1097b

src/Client/Clients/WorkspaceClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using Newtonsoft.Json.Linq;
33
using OmniSharp.Extensions.LanguageServer.Protocol;
44

src/Client/Dispatcher/LspDispatcher.cs

+45-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using Newtonsoft.Json.Linq;
7+
using OmniSharp.Extensions.JsonRpc;
78
using OmniSharp.Extensions.LanguageServer.Client.Handlers;
89

910
namespace OmniSharp.Extensions.LanguageServer.Client.Dispatcher
@@ -21,10 +22,22 @@ public class LspDispatcher
2122
/// <summary>
2223
/// Create a new <see cref="LspDispatcher"/>.
2324
/// </summary>
24-
public LspDispatcher()
25+
/// <param name="serializer">
26+
/// The JSON serialiser for notification / request / response payloads.
27+
/// </param>
28+
public LspDispatcher(ISerializer serializer)
2529
{
30+
if (serializer == null)
31+
throw new ArgumentNullException(nameof(serializer));
32+
33+
Serializer = serializer;
2634
}
2735

36+
/// <summary>
37+
/// The JSON serialiser to use for notification / request / response payloads.
38+
/// </summary>
39+
public ISerializer Serializer { get; set; }
40+
2841
/// <summary>
2942
/// Register a handler invoker.
3043
/// </summary>
@@ -92,7 +105,9 @@ public async Task<bool> TryHandleNotification(string method, JObject notificatio
92105

93106
if (_handlers.TryGetValue(method, out IHandler handler) && handler is IInvokeNotificationHandler notificationHandler)
94107
{
95-
await notificationHandler.Invoke(notification);
108+
object notificationPayload = DeserializePayload(notificationHandler.PayloadType, notification);
109+
110+
await notificationHandler.Invoke(notificationPayload);
96111

97112
return true;
98113
}
@@ -121,9 +136,36 @@ public Task<object> TryHandleRequest(string method, JObject request, Cancellatio
121136
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
122137

123138
if (_handlers.TryGetValue(method, out IHandler handler) && handler is IInvokeRequestHandler requestHandler)
124-
return requestHandler.Invoke(request, cancellationToken);
139+
{
140+
object requestPayload = DeserializePayload(requestHandler.PayloadType, request);
141+
142+
return requestHandler.Invoke(requestPayload, cancellationToken);
143+
}
125144

126145
return null;
127146
}
147+
148+
/// <summary>
149+
/// Deserialise a notification / request payload from JSON.
150+
/// </summary>
151+
/// <param name="payloadType">
152+
/// The payload's CLR type.
153+
/// </param>
154+
/// <param name="payload">
155+
/// JSON representing the payload.
156+
/// </param>
157+
/// <returns>
158+
/// The deserialised payload (if one is present and expected).
159+
/// </returns>
160+
object DeserializePayload(Type payloadType, JObject payload)
161+
{
162+
if (payloadType == null)
163+
throw new ArgumentNullException(nameof(payloadType));
164+
165+
if (payloadType == null || payload == null)
166+
return null;
167+
168+
return payload.ToObject(payloadType, Serializer.JsonSerializer);
169+
}
128170
}
129171
}

0 commit comments

Comments
 (0)