This repository was archived by the owner on Dec 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathHandler.cs
82 lines (67 loc) · 2.61 KB
/
Handler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using LanguageServer.Json;
using System;
using System.Collections.Generic;
using System.Threading;
namespace LanguageServer
{
internal class ResponseHandler
{
private NumberOrString _id;
private readonly Type _responseType;
private readonly ResponseHandlerDelegate _handler;
internal NumberOrString Id => _id;
internal Type ResponseType => _responseType;
internal ResponseHandler(NumberOrString id, Type responseType, ResponseHandlerDelegate handler)
{
_id = id;
_responseType = responseType;
_handler = handler;
}
internal void Handle(object response)
{
_handler(response);
}
}
internal delegate void ResponseHandlerDelegate(object response);
internal class RequestHandler
{
private readonly string _rpcMethod;
private readonly Type _requestType;
private readonly Type _responseType;
private readonly RequestHandlerDelegate _handler;
internal string RpcMethod => _rpcMethod;
internal Type RequestType => _requestType;
internal Type ResponseType => _responseType;
internal RequestHandler(string rpcMethod, Type requestType, Type responseType, RequestHandlerDelegate handler)
{
_rpcMethod = rpcMethod;
_requestType = requestType;
_responseType = responseType;
_handler = handler;
}
internal object Handle(object request, Connection connection, CancellationToken token)
{
return _handler(request, connection, token);
}
}
internal delegate object RequestHandlerDelegate(object request, Connection connection, CancellationToken token);
internal class NotificationHandler
{
private readonly string _rpcMethod;
private readonly Type _notificationType;
private readonly NotificationHandlerDelegate _handler;
internal string RpcMethod => _rpcMethod;
internal Type NotificationType => _notificationType;
internal NotificationHandler(string rpcMethod, Type notificationType, NotificationHandlerDelegate handler)
{
_rpcMethod = rpcMethod;
_notificationType = notificationType;
_handler = handler;
}
internal void Handle(object notification, Connection connection)
{
_handler(notification, connection);
}
}
internal delegate void NotificationHandlerDelegate(object notification, Connection connection);
}