Skip to content

[WIP] bring up to date with latest spec #51

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 15 commits into from
Jan 8, 2018
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions language-server-protocol.sha.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This is the last commit we caught up with https://github.com/Microsoft/language-server-protocol
05e3af34464671a788679080f06558db52d1097b
2 changes: 1 addition & 1 deletion src/Client/Clients/WorkspaceClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.LanguageServer.Protocol;

Expand Down
48 changes: 45 additions & 3 deletions src/Client/Dispatcher/LspDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Client.Handlers;

namespace OmniSharp.Extensions.LanguageServer.Client.Dispatcher
Expand All @@ -21,10 +22,22 @@ public class LspDispatcher
/// <summary>
/// Create a new <see cref="LspDispatcher"/>.
/// </summary>
public LspDispatcher()
/// <param name="serializer">
/// The JSON serialiser for notification / request / response payloads.
/// </param>
public LspDispatcher(ISerializer serializer)
{
if (serializer == null)
throw new ArgumentNullException(nameof(serializer));

Serializer = serializer;
}

/// <summary>
/// The JSON serialiser to use for notification / request / response payloads.
/// </summary>
public ISerializer Serializer { get; set; }

/// <summary>
/// Register a handler invoker.
/// </summary>
Expand Down Expand Up @@ -92,7 +105,9 @@ public async Task<bool> TryHandleNotification(string method, JObject notificatio

if (_handlers.TryGetValue(method, out IHandler handler) && handler is IInvokeNotificationHandler notificationHandler)
{
await notificationHandler.Invoke(notification);
object notificationPayload = DeserializePayload(notificationHandler.PayloadType, notification);

await notificationHandler.Invoke(notificationPayload);

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

if (_handlers.TryGetValue(method, out IHandler handler) && handler is IInvokeRequestHandler requestHandler)
return requestHandler.Invoke(request, cancellationToken);
{
object requestPayload = DeserializePayload(requestHandler.PayloadType, request);

return requestHandler.Invoke(requestPayload, cancellationToken);
}

return null;
}

/// <summary>
/// Deserialise a notification / request payload from JSON.
/// </summary>
/// <param name="payloadType">
/// The payload's CLR type.
/// </param>
/// <param name="payload">
/// JSON representing the payload.
/// </param>
/// <returns>
/// The deserialised payload (if one is present and expected).
/// </returns>
object DeserializePayload(Type payloadType, JObject payload)
{
if (payloadType == null)
throw new ArgumentNullException(nameof(payloadType));

if (payloadType == null || payload == null)
return null;

return payload.ToObject(payloadType, Serializer.JsonSerializer);
}
}
}
Loading